John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // 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 Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_ |
| 8 | #define FPDFSDK_INCLUDE_FSDK_MGR_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 10 | #include <map> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 11 | #include <memory> |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 12 | |
Lei Zhang | a688a04 | 2015-11-09 13:57:49 -0800 | [diff] [blame] | 13 | #include "core/include/fpdftext/fpdf_text.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 14 | #include "fsdk_actionhandler.h" |
| 15 | #include "fsdk_annothandler.h" |
| 16 | #include "fsdk_baseannot.h" |
| 17 | #include "fsdk_baseform.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | #include "fsdk_common.h" |
| 19 | #include "fsdk_define.h" |
| 20 | #include "fx_systemhandler.h" |
Lei Zhang | e5b0bd1 | 2015-06-19 17:15:41 -0700 | [diff] [blame] | 21 | #include "javascript/IJavaScript.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 22 | #include "public/fpdf_formfill.h" |
| 23 | #include "public/fpdf_fwlevent.h" // cross platform keycode and events define. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 25 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 875b9c9 | 2016-01-08 13:51:10 -0800 | [diff] [blame] | 26 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
| 27 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 28 | #endif // PDF_ENABLE_XFA |
| 29 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | class CFFL_IFormFiller; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 31 | class CPDFSDK_ActionHandler; |
| 32 | class CPDFSDK_Annot; |
| 33 | class CPDFSDK_Document; |
| 34 | class CPDFSDK_InterForm; |
| 35 | class CPDFSDK_PageView; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | class CPDFSDK_Widget; |
| 37 | class IFX_SystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | class CPDFDoc_Environment final { |
| 40 | public: |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 41 | CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 42 | ~CPDFDoc_Environment(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 43 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 44 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 45 | void Release() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | if (m_pInfo && m_pInfo->Release) |
| 47 | m_pInfo->Release(m_pInfo); |
| 48 | delete this; |
| 49 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 50 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | |
| 52 | void FFI_Invalidate(FPDF_PAGE page, |
| 53 | double left, |
| 54 | double top, |
| 55 | double right, |
| 56 | double bottom) { |
| 57 | if (m_pInfo && m_pInfo->FFI_Invalidate) |
| 58 | m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); |
| 59 | } |
| 60 | |
| 61 | void FFI_OutputSelectedRect(FPDF_PAGE page, |
| 62 | double left, |
| 63 | double top, |
| 64 | double right, |
| 65 | double bottom) { |
| 66 | if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) |
| 67 | m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); |
| 68 | } |
| 69 | |
| 70 | void FFI_SetCursor(int nCursorType) { |
| 71 | if (m_pInfo && m_pInfo->FFI_SetCursor) |
| 72 | m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); |
| 73 | } |
| 74 | |
| 75 | int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) { |
| 76 | if (m_pInfo && m_pInfo->FFI_SetTimer) |
| 77 | return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | void FFI_KillTimer(int nTimerID) { |
| 82 | if (m_pInfo && m_pInfo->FFI_KillTimer) |
| 83 | m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); |
| 84 | } |
| 85 | |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 86 | FX_SYSTEMTIME FFI_GetLocalTime() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | FX_SYSTEMTIME fxtime; |
| 88 | if (m_pInfo && m_pInfo->FFI_GetLocalTime) { |
| 89 | FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); |
| 90 | fxtime.wDay = systime.wDay; |
| 91 | fxtime.wDayOfWeek = systime.wDayOfWeek; |
| 92 | fxtime.wHour = systime.wHour; |
| 93 | fxtime.wMilliseconds = systime.wMilliseconds; |
| 94 | fxtime.wMinute = systime.wMinute; |
| 95 | fxtime.wMonth = systime.wMonth; |
| 96 | fxtime.wSecond = systime.wSecond; |
| 97 | fxtime.wYear = systime.wYear; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 98 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | return fxtime; |
| 100 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | void FFI_OnChange() { |
| 103 | if (m_pInfo && m_pInfo->FFI_OnChange) |
| 104 | m_pInfo->FFI_OnChange(m_pInfo); |
| 105 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 106 | |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 107 | FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; |
| 109 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 110 | |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 111 | FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; |
| 113 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 114 | |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 115 | FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | return (nFlag & FWL_EVENTFLAG_AltKey) != 0; |
| 117 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 118 | |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 119 | FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | int JS_appAlert(const FX_WCHAR* Msg, |
| 122 | const FX_WCHAR* Title, |
| 123 | FX_UINT Type, |
| 124 | FX_UINT Icon); |
| 125 | int JS_appResponse(const FX_WCHAR* Question, |
| 126 | const FX_WCHAR* Title, |
| 127 | const FX_WCHAR* Default, |
| 128 | const FX_WCHAR* cLabel, |
| 129 | FPDF_BOOL bPassword, |
| 130 | void* response, |
| 131 | int length); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 132 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | void JS_appBeep(int nType) { |
| 134 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep) |
| 135 | m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); |
| 136 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | CFX_WideString JS_fieldBrowse(); |
| 139 | CFX_WideString JS_docGetFilePath(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 140 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 141 | void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); |
| 142 | void JS_docmailForm(void* mailData, |
| 143 | int length, |
| 144 | FPDF_BOOL bUI, |
| 145 | const FX_WCHAR* To, |
| 146 | const FX_WCHAR* Subject, |
| 147 | const FX_WCHAR* CC, |
| 148 | const FX_WCHAR* BCC, |
| 149 | const FX_WCHAR* Msg); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | void JS_docprint(FPDF_BOOL bUI, |
| 152 | int nStart, |
| 153 | int nEnd, |
| 154 | FPDF_BOOL bSilent, |
| 155 | FPDF_BOOL bShrinkToFit, |
| 156 | FPDF_BOOL bPrintAsImage, |
| 157 | FPDF_BOOL bReverse, |
| 158 | FPDF_BOOL bAnnotations) { |
| 159 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print) |
| 160 | m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, |
| 161 | nEnd, bSilent, bShrinkToFit, |
| 162 | bPrintAsImage, bReverse, bAnnotations); |
| 163 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | void JS_docgotoPage(int nPageNum) { |
| 166 | if (m_pInfo && m_pInfo->m_pJsPlatform && |
| 167 | m_pInfo->m_pJsPlatform->Doc_gotoPage) |
| 168 | m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); |
| 169 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 170 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) { |
| 172 | if (m_pInfo && m_pInfo->FFI_GetPage) |
| 173 | return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); |
| 174 | return NULL; |
| 175 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 176 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) { |
| 178 | if (m_pInfo && m_pInfo->FFI_GetCurrentPage) |
| 179 | return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); |
| 180 | return NULL; |
| 181 | } |
Tom Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | int FFI_GetRotation(FPDF_PAGE page) { |
| 184 | if (m_pInfo && m_pInfo->FFI_GetRotation) |
| 185 | return m_pInfo->FFI_GetRotation(m_pInfo, page); |
| 186 | return 0; |
| 187 | } |
Tom Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 188 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) { |
| 190 | if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) |
| 191 | m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); |
| 192 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 193 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | void FFI_OnSetFieldInputFocus(void* field, |
| 195 | FPDF_WIDESTRING focusText, |
| 196 | FPDF_DWORD nTextLen, |
| 197 | FX_BOOL bFocus) { |
| 198 | if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) |
| 199 | m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); |
| 200 | } |
Tom Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | void FFI_DoURIAction(const FX_CHAR* bsURI) { |
| 203 | if (m_pInfo && m_pInfo->FFI_DoURIAction) |
| 204 | m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); |
| 205 | } |
Tom Sepez | 0d3b5cc | 2014-07-30 13:03:52 -0700 | [diff] [blame] | 206 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | void FFI_DoGoToAction(int nPageIndex, |
| 208 | int zoomMode, |
| 209 | float* fPosArray, |
| 210 | int sizeOfArray) { |
| 211 | if (m_pInfo && m_pInfo->FFI_DoGoToAction) |
| 212 | m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, |
| 213 | sizeOfArray); |
| 214 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 216 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | void FFI_DisplayCaret(FPDF_PAGE page, |
| 218 | FPDF_BOOL bVisible, |
| 219 | double left, |
| 220 | double top, |
| 221 | double right, |
| 222 | double bottom) { |
| 223 | if (m_pInfo && m_pInfo->FFI_DisplayCaret) |
| 224 | m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, |
| 225 | bottom); |
| 226 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 227 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) { |
Jun Fang | 01fe588 | 2015-11-25 11:05:58 +0800 | [diff] [blame] | 229 | if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) { |
| 230 | return -1; |
| 231 | } |
| 232 | return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 233 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 234 | |
Jun Fang | 01fe588 | 2015-11-25 11:05:58 +0800 | [diff] [blame] | 235 | void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | if (m_pInfo && m_pInfo->FFI_SetCurrentPage) |
| 237 | m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 238 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | CFX_WideString FFI_GetPlatform() { |
| 243 | if (m_pInfo && m_pInfo->FFI_GetPlatform) { |
| 244 | int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0); |
| 245 | if (nRequiredLen <= 0) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 246 | return L""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 247 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | char* pbuff = new char[nRequiredLen]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | memset(pbuff, 0, nRequiredLen); |
| 250 | int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); |
| 251 | if (nActualLen <= 0 || nActualLen > nRequiredLen) { |
| 252 | delete[] pbuff; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 253 | return L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | } |
| 255 | CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); |
| 256 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 257 | (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), |
| 258 | bsRet.GetLength() / sizeof(unsigned short)); |
| 259 | delete[] pbuff; |
| 260 | return wsRet; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 261 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | return L""; |
| 263 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 264 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | void FFI_GotoURL(FPDF_DOCUMENT document, |
| 266 | const CFX_WideStringC& wsURL, |
| 267 | FX_BOOL bAppend) { |
| 268 | if (m_pInfo && m_pInfo->FFI_GotoURL) { |
| 269 | CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 270 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); |
| 271 | m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); |
| 272 | bsTo.ReleaseBuffer(); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 273 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 274 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) { |
| 277 | wsURL = CFX_WideString(); |
| 278 | } |
| 279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {} |
| 281 | |
| 282 | void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) { |
| 283 | if (m_pInfo && m_pInfo->FFI_GetPageViewRect) { |
| 284 | double left; |
| 285 | double top; |
| 286 | double right; |
| 287 | double bottom; |
| 288 | m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); |
| 289 | |
| 290 | dstRect.left = static_cast<float>(left); |
| 291 | dstRect.top = static_cast<float>(top < bottom ? bottom : top); |
| 292 | dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); |
| 293 | dstRect.right = static_cast<float>(right); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 294 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 296 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | FX_BOOL FFI_PopupMenu(FPDF_PAGE page, |
| 298 | FPDF_WIDGET hWidget, |
| 299 | int menuFlag, |
| 300 | CFX_PointF ptPopup, |
| 301 | const CFX_PointF* pRectExclude) { |
| 302 | if (m_pInfo && m_pInfo->FFI_PopupMenu) |
| 303 | return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, |
| 304 | ptPopup.y); |
| 305 | return FALSE; |
| 306 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 307 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | void FFI_Alert(FPDF_WIDESTRING Msg, |
| 309 | FPDF_WIDESTRING Title, |
| 310 | int Type, |
| 311 | int Icon) { |
| 312 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) |
| 313 | m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, |
| 314 | Type, Icon); |
| 315 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 316 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, |
| 318 | FPDF_WIDESTRING pTo, |
| 319 | FPDF_WIDESTRING pSubject, |
| 320 | FPDF_WIDESTRING pCC, |
| 321 | FPDF_WIDESTRING pBcc, |
| 322 | FPDF_WIDESTRING pMsg) { |
| 323 | if (m_pInfo && m_pInfo->FFI_EmailTo) |
| 324 | m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, |
| 325 | pMsg); |
| 326 | } |
| 327 | |
| 328 | void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, |
| 329 | int fileFlag, |
| 330 | FPDF_WIDESTRING uploadTo) { |
| 331 | if (m_pInfo && m_pInfo->FFI_UploadTo) |
| 332 | m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); |
| 333 | } |
| 334 | |
| 335 | FPDF_FILEHANDLER* FFI_OpenFile(int fileType, |
| 336 | FPDF_WIDESTRING wsURL, |
| 337 | const char* mode) { |
| 338 | if (m_pInfo && m_pInfo->FFI_OpenFile) |
| 339 | return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); |
| 340 | return NULL; |
| 341 | } |
| 342 | |
| 343 | CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const { |
| 344 | return L""; |
| 345 | } |
| 346 | |
| 347 | int FFI_GetDocumentCount() const { return 0; } |
| 348 | int FFI_GetCurDocument() const { return 0; } |
| 349 | |
| 350 | IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) { |
| 351 | if (m_pInfo && m_pInfo->FFI_DownloadFromURL) { |
| 352 | CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); |
| 353 | FPDF_WIDESTRING wsURL = |
| 354 | (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); |
| 355 | |
| 356 | FPDF_LPFILEHANDLER fileHandler = |
| 357 | m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); |
| 358 | |
Lei Zhang | db5256f | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 359 | return new CFPDF_FileStream(fileHandler); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | } |
| 361 | return NULL; |
| 362 | } |
| 363 | |
| 364 | CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, |
| 365 | const FX_WCHAR* wsData, |
| 366 | const FX_WCHAR* wsContentType, |
| 367 | const FX_WCHAR* wsEncode, |
| 368 | const FX_WCHAR* wsHeader) { |
| 369 | if (m_pInfo && m_pInfo->FFI_PostRequestURL) { |
| 370 | CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 371 | FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
| 372 | |
| 373 | CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
| 374 | FPDF_WIDESTRING data = |
| 375 | (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
| 376 | |
| 377 | CFX_ByteString bsContentType = |
| 378 | CFX_WideString(wsContentType).UTF16LE_Encode(); |
| 379 | FPDF_WIDESTRING contentType = |
| 380 | (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); |
| 381 | |
| 382 | CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
| 383 | FPDF_WIDESTRING encode = |
| 384 | (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
| 385 | |
| 386 | CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); |
| 387 | FPDF_WIDESTRING header = |
| 388 | (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); |
| 389 | |
| 390 | FPDF_BSTR respone; |
| 391 | FPDF_BStr_Init(&respone); |
| 392 | m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, |
| 393 | header, &respone); |
| 394 | |
| 395 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 396 | (unsigned short*)respone.str, respone.len / sizeof(unsigned short)); |
| 397 | FPDF_BStr_Clear(&respone); |
| 398 | |
| 399 | return wsRet; |
| 400 | } |
| 401 | return L""; |
| 402 | } |
| 403 | |
| 404 | FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, |
| 405 | const FX_WCHAR* wsData, |
| 406 | const FX_WCHAR* wsEncode) { |
| 407 | if (m_pInfo && m_pInfo->FFI_PutRequestURL) { |
| 408 | CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 409 | FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
| 410 | |
| 411 | CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
| 412 | FPDF_WIDESTRING data = |
| 413 | (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
| 414 | |
| 415 | CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
| 416 | FPDF_WIDESTRING encode = |
| 417 | (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
| 418 | |
| 419 | return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); |
| 420 | } |
| 421 | return FALSE; |
| 422 | } |
| 423 | |
| 424 | FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle, |
| 425 | const FX_WCHAR* wsFilter, |
| 426 | CFX_WideStringArray& wsPathArr, |
| 427 | FX_BOOL bOpen) { |
| 428 | return FALSE; |
| 429 | } |
| 430 | |
| 431 | CFX_WideString FFI_GetLanguage() { |
| 432 | if (m_pInfo && m_pInfo->FFI_GetLanguage) { |
| 433 | int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0); |
| 434 | if (nRequiredLen <= 0) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 435 | return L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 436 | |
| 437 | char* pbuff = new char[nRequiredLen]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 438 | memset(pbuff, 0, nRequiredLen); |
| 439 | int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); |
| 440 | if (nActualLen <= 0 || nActualLen > nRequiredLen) { |
| 441 | delete[] pbuff; |
| 442 | return L""; |
| 443 | } |
| 444 | CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); |
| 445 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 446 | (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), |
| 447 | bsRet.GetLength() / sizeof(unsigned short)); |
| 448 | delete[] pbuff; |
| 449 | return wsRet; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 450 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 451 | return L""; |
| 452 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 453 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 454 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } |
| 456 | void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } |
| 457 | CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 458 | UnderlyingDocumentType* GetUnderlyingDocument() const { |
| 459 | return m_pUnderlyingDoc; |
| 460 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | CFX_ByteString GetAppName() const { return ""; } |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 462 | IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 464 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. |
| 466 | CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 467 | IJS_Runtime* GetJSRuntime(); // Creates if not present. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 469 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | private: |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 471 | std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr; |
| 472 | std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; |
| 473 | std::unique_ptr<IJS_Runtime> m_pJSRuntime; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | FPDF_FORMFILLINFO* const m_pInfo; |
| 475 | CPDFSDK_Document* m_pSDKDoc; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 476 | UnderlyingDocumentType* const m_pUnderlyingDoc; |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 477 | std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller; |
| 478 | std::unique_ptr<IFX_SystemHandler> m_pSysHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 479 | }; |
| 480 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | class CPDFSDK_Document { |
| 482 | public: |
Tom Sepez | fe351db | 2016-01-29 16:26:27 -0800 | [diff] [blame] | 483 | static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle); |
| 484 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 485 | CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | ~CPDFSDK_Document(); |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 487 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 488 | CPDFSDK_InterForm* GetInterForm(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 489 | |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 490 | // Gets the document object for the next layer down; for master this is |
| 491 | // a CPDF_Document, but for XFA it is a CPDFXFA_Document. |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 492 | UnderlyingDocumentType* GetUnderlyingDocument() const { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 493 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 494 | return GetXFADocument(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 495 | #else // PDF_ENABLE_XFA |
| 496 | return GetPDFDocument(); |
| 497 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 498 | } |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 499 | |
| 500 | // Gets the CPDF_Document, either directly in master, or from the |
| 501 | // CPDFXFA_Document for XFA. |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 502 | CPDF_Document* GetPDFDocument() const { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 503 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 504 | return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 505 | #else // PDF_ENABLE_XFA |
| 506 | return m_pDoc; |
| 507 | #endif // PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 508 | } |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 509 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 510 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 511 | // Gets the XFA document directly (XFA-only). |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 512 | CPDFXFA_Document* GetXFADocument() const { return m_pDoc; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 513 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | int GetPageViewCount() const { return m_pageMap.size(); } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 515 | #endif // PDF_ENABLE_XFA |
| 516 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 517 | CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | FX_BOOL ReNew = TRUE); |
| 519 | CPDFSDK_PageView* GetPageView(int nIndex); |
| 520 | CPDFSDK_PageView* GetCurrentView(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 521 | void RemovePageView(UnderlyingPageType* pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 523 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | CPDFSDK_Annot* GetFocusAnnot(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 525 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 526 | IJS_Runtime* GetJsRuntime(); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 527 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); |
| 529 | FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 530 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 531 | FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages, |
| 532 | CPDF_Document* pDstDoc); |
| 533 | FX_BOOL InsertPages(int nInsertAt, |
| 534 | const CPDF_Document* pSrcDoc, |
| 535 | const CFX_WordArray& arrSrcPages); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | FX_BOOL ReplacePages(int nPage, |
| 537 | const CPDF_Document* pSrcDoc, |
| 538 | const CFX_WordArray& arrSrcPages); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 539 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 540 | void OnCloseDocument(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 541 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 542 | int GetPageCount() { return m_pDoc->GetPageCount(); } |
| 543 | FX_BOOL GetPermissions(int nFlag); |
| 544 | FX_BOOL GetChangeMark() { return m_bChangeMask; } |
| 545 | void SetChangeMark() { m_bChangeMask = TRUE; } |
| 546 | void ClearChangeMark() { m_bChangeMask = FALSE; } |
| 547 | CFX_WideString GetPath(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 548 | UnderlyingPageType* GetPage(int nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 549 | CPDFDoc_Environment* GetEnv() { return m_pEnv; } |
| 550 | void ProcJavascriptFun(); |
| 551 | FX_BOOL ProcOpenAction(); |
| 552 | CPDF_OCContext* GetOCContext(); |
| 553 | |
| 554 | private: |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 555 | std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 556 | UnderlyingDocumentType* m_pDoc; |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 557 | std::unique_ptr<CPDFSDK_InterForm> m_pInterForm; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 558 | CPDFSDK_Annot* m_pFocusAnnot; |
| 559 | CPDFDoc_Environment* m_pEnv; |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 560 | std::unique_ptr<CPDF_OCContext> m_pOccontent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | FX_BOOL m_bChangeMask; |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 562 | FX_BOOL m_bBeingDestroyed; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 563 | }; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | class CPDFSDK_PageView final { |
| 565 | public: |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 566 | CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 567 | ~CPDFSDK_PageView(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 568 | |
| 569 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | void PageView_OnDraw(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 571 | CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | CPDF_RenderOptions* pOptions, |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame] | 573 | const FX_RECT& pClip); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 574 | #else // PDF_ENABLE_XFA |
| 575 | void PageView_OnDraw(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 576 | CFX_Matrix* pUser2Device, |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 577 | CPDF_RenderOptions* pOptions); |
| 578 | #endif // PDF_ENABLE_XFA |
| 579 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 580 | const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 582 | const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 583 | CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
| 584 | CPDFSDK_Annot* GetFocusAnnot(); |
| 585 | void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) { |
| 586 | m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag); |
| 587 | } |
| 588 | FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) { |
| 589 | return m_pSDKDoc->KillFocusAnnot(nFlag); |
| 590 | } |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 591 | void KillFocusAnnotIfNeeded(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 592 | FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 593 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict); |
| 595 | CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict); |
| 596 | CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 597 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 598 | FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 599 | size_t CountAnnots() const; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 600 | CPDFSDK_Annot* GetAnnot(size_t nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 602 | |
| 603 | #ifdef PDF_ENABLE_XFA |
| 604 | CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget); |
| 606 | CPDFXFA_Page* GetPDFXFAPage() { return m_page; } |
| 607 | CPDF_Page* GetPDFPage(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 608 | #else |
| 609 | CPDF_Page* GetPDFPage() { return m_page; } |
| 610 | #endif // PDF_ENABLE_XFA |
| 611 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | CPDF_Document* GetPDFDocument(); |
| 613 | CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; } |
| 614 | FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag); |
| 615 | FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 616 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag); |
| 618 | FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 619 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 620 | FX_BOOL OnChar(int nChar, FX_UINT nFlag); |
| 621 | FX_BOOL OnKeyDown(int nKeyCode, int nFlag); |
| 622 | FX_BOOL OnKeyUp(int nKeyCode, int nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 623 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 624 | FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag); |
| 625 | FX_BOOL OnMouseWheel(double deltaX, |
| 626 | double deltaY, |
| 627 | const CPDF_Point& point, |
| 628 | int nFlag); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 629 | bool IsValidAnnot(const CPDF_Annot* p) const; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 630 | void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | void UpdateRects(CFX_RectArray& rects); |
| 632 | void UpdateView(CPDFSDK_Annot* pAnnot); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 633 | const std::vector<CPDFSDK_Annot*>& GetAnnotList() const { |
| 634 | return m_fxAnnotArray; |
| 635 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 636 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | int GetPageIndex(); |
| 638 | void LoadFXAnnots(); |
Jun Fang | 7523954 | 2016-01-20 08:04:47 +0800 | [diff] [blame] | 639 | void ClearFXAnnots(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | void SetValid(FX_BOOL bValid) { m_bValid = bValid; } |
| 641 | FX_BOOL IsValid() { return m_bValid; } |
| 642 | void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; } |
| 643 | FX_BOOL IsLocked() { return m_bLocked; } |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 644 | #ifndef PDF_ENABLE_XFA |
| 645 | void TakeOverPage() { m_bTakeOverPage = TRUE; } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 646 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 647 | |
| 648 | private: |
| 649 | void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, |
| 650 | CPDFSDK_Widget* pWidget); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 651 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 652 | CFX_Matrix m_curMatrix; |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 653 | UnderlyingPageType* m_page; |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 654 | std::unique_ptr<CPDF_AnnotList> m_pAnnotList; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 655 | std::vector<CPDFSDK_Annot*> m_fxAnnotArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | CPDFSDK_Document* m_pSDKDoc; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 657 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 658 | CPDFSDK_Annot* m_CaptureWidget; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 659 | #else // PDF_ENABLE_XFA |
| 660 | CPDFSDK_Widget* m_CaptureWidget; |
| 661 | FX_BOOL m_bTakeOverPage; |
| 662 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 663 | FX_BOOL m_bEnterWidget; |
| 664 | FX_BOOL m_bExitWidget; |
| 665 | FX_BOOL m_bOnWidget; |
| 666 | FX_BOOL m_bValid; |
| 667 | FX_BOOL m_bLocked; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 668 | }; |
| 669 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | template <class TYPE> |
| 671 | class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> { |
| 672 | public: |
| 673 | CGW_ArrayTemplate() {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 674 | ~CGW_ArrayTemplate() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 675 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 677 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 678 | void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) { |
| 679 | int nSize = this->GetSize(); |
| 680 | QuickSort(0, nSize - 1, bAscent, pCompare); |
| 681 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 682 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | private: |
| 684 | void QuickSort(FX_UINT nStartPos, |
| 685 | FX_UINT nStopPos, |
| 686 | FX_BOOL bAscend, |
| 687 | LP_COMPARE pCompare) { |
| 688 | if (nStartPos >= nStopPos) |
| 689 | return; |
| 690 | |
| 691 | if ((nStopPos - nStartPos) == 1) { |
| 692 | TYPE Value1 = this->GetAt(nStartPos); |
| 693 | TYPE Value2 = this->GetAt(nStopPos); |
| 694 | |
| 695 | int iGreate = (*pCompare)(Value1, Value2); |
| 696 | if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { |
| 697 | this->SetAt(nStartPos, Value2); |
| 698 | this->SetAt(nStopPos, Value1); |
| 699 | } |
| 700 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 701 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 702 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 703 | FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; |
| 704 | FX_UINT i = nStartPos; |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 705 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | TYPE Value = this->GetAt(m); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 707 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | while (i < m) { |
| 709 | TYPE temp = this->GetAt(i); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 710 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | int iGreate = (*pCompare)(temp, Value); |
| 712 | if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { |
| 713 | this->InsertAt(m + 1, temp); |
| 714 | this->RemoveAt(i); |
| 715 | m--; |
| 716 | } else { |
| 717 | i++; |
| 718 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 719 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 720 | |
| 721 | FX_UINT j = nStopPos; |
| 722 | |
| 723 | while (j > m) { |
| 724 | TYPE temp = this->GetAt(j); |
| 725 | |
| 726 | int iGreate = (*pCompare)(temp, Value); |
| 727 | if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) { |
| 728 | this->RemoveAt(j); |
| 729 | this->InsertAt(m, temp); |
| 730 | m++; |
| 731 | } else { |
| 732 | j--; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | if (nStartPos < m) |
| 737 | QuickSort(nStartPos, m, bAscend, pCompare); |
| 738 | if (nStopPos > m) |
| 739 | QuickSort(m, nStopPos, bAscend, pCompare); |
| 740 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 741 | }; |
| 742 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 743 | #endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ |