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> |
| 11 | |
Lei Zhang | a688a04 | 2015-11-09 13:57:49 -0800 | [diff] [blame] | 12 | #include "core/include/fpdftext/fpdf_text.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 13 | #include "fsdk_actionhandler.h" |
| 14 | #include "fsdk_annothandler.h" |
| 15 | #include "fsdk_baseannot.h" |
| 16 | #include "fsdk_baseform.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | #include "fsdk_common.h" |
| 18 | #include "fsdk_define.h" |
| 19 | #include "fx_systemhandler.h" |
Lei Zhang | e5b0bd1 | 2015-06-19 17:15:41 -0700 | [diff] [blame] | 20 | #include "javascript/IJavaScript.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 21 | #include "public/fpdf_formfill.h" |
| 22 | #include "public/fpdf_fwlevent.h" // cross platform keycode and events define. |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 23 | #include "third_party/base/nonstd_unique_ptr.h" |
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 |
| 26 | #include "fpdfxfa/fpdfxfa_doc.h" |
| 27 | #include "fpdfxfa/fpdfxfa_page.h" |
| 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 | |
| 280 | void FFI_AddDoRecord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) {} |
| 281 | void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {} |
| 282 | |
| 283 | void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) { |
| 284 | if (m_pInfo && m_pInfo->FFI_GetPageViewRect) { |
| 285 | double left; |
| 286 | double top; |
| 287 | double right; |
| 288 | double bottom; |
| 289 | m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); |
| 290 | |
| 291 | dstRect.left = static_cast<float>(left); |
| 292 | dstRect.top = static_cast<float>(top < bottom ? bottom : top); |
| 293 | dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); |
| 294 | dstRect.right = static_cast<float>(right); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 295 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 297 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | FX_BOOL FFI_PopupMenu(FPDF_PAGE page, |
| 299 | FPDF_WIDGET hWidget, |
| 300 | int menuFlag, |
| 301 | CFX_PointF ptPopup, |
| 302 | const CFX_PointF* pRectExclude) { |
| 303 | if (m_pInfo && m_pInfo->FFI_PopupMenu) |
| 304 | return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, |
| 305 | ptPopup.y); |
| 306 | return FALSE; |
| 307 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 308 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 309 | void FFI_Alert(FPDF_WIDESTRING Msg, |
| 310 | FPDF_WIDESTRING Title, |
| 311 | int Type, |
| 312 | int Icon) { |
| 313 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) |
| 314 | m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, |
| 315 | Type, Icon); |
| 316 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 318 | void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, |
| 319 | FPDF_WIDESTRING pTo, |
| 320 | FPDF_WIDESTRING pSubject, |
| 321 | FPDF_WIDESTRING pCC, |
| 322 | FPDF_WIDESTRING pBcc, |
| 323 | FPDF_WIDESTRING pMsg) { |
| 324 | if (m_pInfo && m_pInfo->FFI_EmailTo) |
| 325 | m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, |
| 326 | pMsg); |
| 327 | } |
| 328 | |
| 329 | void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, |
| 330 | int fileFlag, |
| 331 | FPDF_WIDESTRING uploadTo) { |
| 332 | if (m_pInfo && m_pInfo->FFI_UploadTo) |
| 333 | m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); |
| 334 | } |
| 335 | |
| 336 | FPDF_FILEHANDLER* FFI_OpenFile(int fileType, |
| 337 | FPDF_WIDESTRING wsURL, |
| 338 | const char* mode) { |
| 339 | if (m_pInfo && m_pInfo->FFI_OpenFile) |
| 340 | return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); |
| 341 | return NULL; |
| 342 | } |
| 343 | |
| 344 | CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const { |
| 345 | return L""; |
| 346 | } |
| 347 | |
| 348 | int FFI_GetDocumentCount() const { return 0; } |
| 349 | int FFI_GetCurDocument() const { return 0; } |
| 350 | |
| 351 | IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) { |
| 352 | if (m_pInfo && m_pInfo->FFI_DownloadFromURL) { |
| 353 | CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); |
| 354 | FPDF_WIDESTRING wsURL = |
| 355 | (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); |
| 356 | |
| 357 | FPDF_LPFILEHANDLER fileHandler = |
| 358 | m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); |
| 359 | |
Lei Zhang | db5256f | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 360 | return new CFPDF_FileStream(fileHandler); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 361 | } |
| 362 | return NULL; |
| 363 | } |
| 364 | |
| 365 | CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, |
| 366 | const FX_WCHAR* wsData, |
| 367 | const FX_WCHAR* wsContentType, |
| 368 | const FX_WCHAR* wsEncode, |
| 369 | const FX_WCHAR* wsHeader) { |
| 370 | if (m_pInfo && m_pInfo->FFI_PostRequestURL) { |
| 371 | CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 372 | FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
| 373 | |
| 374 | CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
| 375 | FPDF_WIDESTRING data = |
| 376 | (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
| 377 | |
| 378 | CFX_ByteString bsContentType = |
| 379 | CFX_WideString(wsContentType).UTF16LE_Encode(); |
| 380 | FPDF_WIDESTRING contentType = |
| 381 | (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); |
| 382 | |
| 383 | CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
| 384 | FPDF_WIDESTRING encode = |
| 385 | (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
| 386 | |
| 387 | CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); |
| 388 | FPDF_WIDESTRING header = |
| 389 | (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); |
| 390 | |
| 391 | FPDF_BSTR respone; |
| 392 | FPDF_BStr_Init(&respone); |
| 393 | m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, |
| 394 | header, &respone); |
| 395 | |
| 396 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 397 | (unsigned short*)respone.str, respone.len / sizeof(unsigned short)); |
| 398 | FPDF_BStr_Clear(&respone); |
| 399 | |
| 400 | return wsRet; |
| 401 | } |
| 402 | return L""; |
| 403 | } |
| 404 | |
| 405 | FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, |
| 406 | const FX_WCHAR* wsData, |
| 407 | const FX_WCHAR* wsEncode) { |
| 408 | if (m_pInfo && m_pInfo->FFI_PutRequestURL) { |
| 409 | CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
| 410 | FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
| 411 | |
| 412 | CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
| 413 | FPDF_WIDESTRING data = |
| 414 | (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
| 415 | |
| 416 | CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
| 417 | FPDF_WIDESTRING encode = |
| 418 | (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
| 419 | |
| 420 | return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); |
| 421 | } |
| 422 | return FALSE; |
| 423 | } |
| 424 | |
| 425 | FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle, |
| 426 | const FX_WCHAR* wsFilter, |
| 427 | CFX_WideStringArray& wsPathArr, |
| 428 | FX_BOOL bOpen) { |
| 429 | return FALSE; |
| 430 | } |
| 431 | |
| 432 | CFX_WideString FFI_GetLanguage() { |
| 433 | if (m_pInfo && m_pInfo->FFI_GetLanguage) { |
| 434 | int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0); |
| 435 | if (nRequiredLen <= 0) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 436 | return L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | |
| 438 | char* pbuff = new char[nRequiredLen]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | memset(pbuff, 0, nRequiredLen); |
| 440 | int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); |
| 441 | if (nActualLen <= 0 || nActualLen > nRequiredLen) { |
| 442 | delete[] pbuff; |
| 443 | return L""; |
| 444 | } |
| 445 | CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); |
| 446 | CFX_WideString wsRet = CFX_WideString::FromUTF16LE( |
| 447 | (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), |
| 448 | bsRet.GetLength() / sizeof(unsigned short)); |
| 449 | delete[] pbuff; |
| 450 | return wsRet; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 451 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | return L""; |
| 453 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 454 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 455 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } |
| 457 | void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } |
| 458 | CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 459 | UnderlyingDocumentType* GetUnderlyingDocument() const { |
| 460 | return m_pUnderlyingDoc; |
| 461 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 462 | CFX_ByteString GetAppName() const { return ""; } |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 463 | IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 464 | FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 465 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. |
| 467 | CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 468 | IJS_Runtime* GetJSRuntime(); // Creates if not present. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 470 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | private: |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 472 | nonstd::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr; |
| 473 | nonstd::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 474 | nonstd::unique_ptr<IJS_Runtime> m_pJSRuntime; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | FPDF_FORMFILLINFO* const m_pInfo; |
| 476 | CPDFSDK_Document* m_pSDKDoc; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 477 | UnderlyingDocumentType* const m_pUnderlyingDoc; |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 478 | nonstd::unique_ptr<CFFL_IFormFiller> m_pIFormFiller; |
| 479 | nonstd::unique_ptr<IFX_SystemHandler> m_pSysHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 480 | }; |
| 481 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | class CPDFSDK_Document { |
| 483 | public: |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 484 | CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 485 | ~CPDFSDK_Document(); |
Tom Sepez | 2f3dfef | 2015-03-02 15:35:26 -0800 | [diff] [blame] | 486 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | CPDFSDK_InterForm* GetInterForm(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 488 | |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 489 | // Gets the document object for the next layer down; for master this is |
| 490 | // a CPDF_Document, but for XFA it is a CPDFXFA_Document. |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 491 | UnderlyingDocumentType* GetUnderlyingDocument() const { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 492 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 493 | return GetXFADocument(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 494 | #else // PDF_ENABLE_XFA |
| 495 | return GetPDFDocument(); |
| 496 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 497 | } |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 498 | |
| 499 | // Gets the CPDF_Document, either directly in master, or from the |
| 500 | // CPDFXFA_Document for XFA. |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 501 | CPDF_Document* GetPDFDocument() const { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 502 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 503 | return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 504 | #else // PDF_ENABLE_XFA |
| 505 | return m_pDoc; |
| 506 | #endif // PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 507 | } |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 508 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 509 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 5259ef3 | 2015-11-24 10:21:01 -0800 | [diff] [blame] | 510 | // Gets the XFA document directly (XFA-only). |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 511 | CPDFXFA_Document* GetXFADocument() const { return m_pDoc; } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 512 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | int GetPageViewCount() const { return m_pageMap.size(); } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 514 | #endif // PDF_ENABLE_XFA |
| 515 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 516 | CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 517 | FX_BOOL ReNew = TRUE); |
| 518 | CPDFSDK_PageView* GetPageView(int nIndex); |
| 519 | CPDFSDK_PageView* GetCurrentView(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 520 | void RemovePageView(UnderlyingPageType* pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 521 | void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 522 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 523 | CPDFSDK_Annot* GetFocusAnnot(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 524 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 525 | IJS_Runtime* GetJsRuntime(); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 526 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); |
| 528 | FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 529 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 530 | FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages, |
| 531 | CPDF_Document* pDstDoc); |
| 532 | FX_BOOL InsertPages(int nInsertAt, |
| 533 | const CPDF_Document* pSrcDoc, |
| 534 | const CFX_WordArray& arrSrcPages); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | FX_BOOL ReplacePages(int nPage, |
| 536 | const CPDF_Document* pSrcDoc, |
| 537 | const CFX_WordArray& arrSrcPages); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | void OnCloseDocument(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 540 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | int GetPageCount() { return m_pDoc->GetPageCount(); } |
| 542 | FX_BOOL GetPermissions(int nFlag); |
| 543 | FX_BOOL GetChangeMark() { return m_bChangeMask; } |
| 544 | void SetChangeMark() { m_bChangeMask = TRUE; } |
| 545 | void ClearChangeMark() { m_bChangeMask = FALSE; } |
| 546 | CFX_WideString GetPath(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 547 | UnderlyingPageType* GetPage(int nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 548 | CPDFDoc_Environment* GetEnv() { return m_pEnv; } |
| 549 | void ProcJavascriptFun(); |
| 550 | FX_BOOL ProcOpenAction(); |
| 551 | CPDF_OCContext* GetOCContext(); |
| 552 | |
| 553 | private: |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 554 | std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 555 | UnderlyingDocumentType* m_pDoc; |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 556 | nonstd::unique_ptr<CPDFSDK_InterForm> m_pInterForm; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | CPDFSDK_Annot* m_pFocusAnnot; |
| 558 | CPDFDoc_Environment* m_pEnv; |
Oliver Chang | 2475249 | 2015-10-30 16:08:20 -0700 | [diff] [blame] | 559 | nonstd::unique_ptr<CPDF_OCContext> m_pOccontent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 560 | FX_BOOL m_bChangeMask; |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 561 | FX_BOOL m_bBeingDestroyed; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 562 | }; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 563 | class CPDFSDK_PageView final { |
| 564 | public: |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 565 | CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 566 | ~CPDFSDK_PageView(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 567 | |
| 568 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | void PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 570 | CPDF_Matrix* pUser2Device, |
| 571 | CPDF_RenderOptions* pOptions, |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame] | 572 | const FX_RECT& pClip); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 573 | #else // PDF_ENABLE_XFA |
| 574 | void PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 575 | CPDF_Matrix* pUser2Device, |
| 576 | CPDF_RenderOptions* pOptions); |
| 577 | #endif // PDF_ENABLE_XFA |
| 578 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 579 | const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 581 | const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 582 | CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
| 583 | CPDFSDK_Annot* GetFocusAnnot(); |
| 584 | void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) { |
| 585 | m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag); |
| 586 | } |
| 587 | FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) { |
| 588 | return m_pSDKDoc->KillFocusAnnot(nFlag); |
| 589 | } |
Oliver Chang | 972b78d | 2015-10-30 12:59:29 -0700 | [diff] [blame] | 590 | void KillFocusAnnotIfNeeded(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 591 | FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 592 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 593 | CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict); |
| 594 | CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict); |
| 595 | CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 596 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 597 | FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 598 | size_t CountAnnots() const; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 599 | CPDFSDK_Annot* GetAnnot(size_t nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 600 | CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 601 | |
| 602 | #ifdef PDF_ENABLE_XFA |
| 603 | CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget); |
| 605 | CPDFXFA_Page* GetPDFXFAPage() { return m_page; } |
| 606 | CPDF_Page* GetPDFPage(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 607 | #else |
| 608 | CPDF_Page* GetPDFPage() { return m_page; } |
| 609 | #endif // PDF_ENABLE_XFA |
| 610 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 611 | CPDF_Document* GetPDFDocument(); |
| 612 | CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; } |
| 613 | FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag); |
| 614 | FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 615 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 616 | FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag); |
| 617 | FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 618 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 619 | FX_BOOL OnChar(int nChar, FX_UINT nFlag); |
| 620 | FX_BOOL OnKeyDown(int nKeyCode, int nFlag); |
| 621 | FX_BOOL OnKeyUp(int nKeyCode, int nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 622 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag); |
| 624 | FX_BOOL OnMouseWheel(double deltaX, |
| 625 | double deltaY, |
| 626 | const CPDF_Point& point, |
| 627 | int nFlag); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 628 | bool IsValidAnnot(const CPDF_Annot* p) const; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | void GetCurrentMatrix(CPDF_Matrix& matrix) { matrix = m_curMatrix; } |
| 630 | void UpdateRects(CFX_RectArray& rects); |
| 631 | void UpdateView(CPDFSDK_Annot* pAnnot); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 632 | const std::vector<CPDFSDK_Annot*>& GetAnnotList() const { |
| 633 | return m_fxAnnotArray; |
| 634 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | int GetPageIndex(); |
| 637 | void LoadFXAnnots(); |
| 638 | void SetValid(FX_BOOL bValid) { m_bValid = bValid; } |
| 639 | FX_BOOL IsValid() { return m_bValid; } |
| 640 | void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; } |
| 641 | FX_BOOL IsLocked() { return m_bLocked; } |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 642 | #ifndef PDF_ENABLE_XFA |
| 643 | void TakeOverPage() { m_bTakeOverPage = TRUE; } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 644 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | |
| 646 | private: |
| 647 | void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, |
| 648 | CPDFSDK_Widget* pWidget); |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 649 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | CPDF_Matrix m_curMatrix; |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 651 | UnderlyingPageType* m_page; |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 652 | nonstd::unique_ptr<CPDF_AnnotList> m_pAnnotList; |
| 653 | std::vector<CPDFSDK_Annot*> m_fxAnnotArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | CPDFSDK_Document* m_pSDKDoc; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 655 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | CPDFSDK_Annot* m_CaptureWidget; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame^] | 657 | #else // PDF_ENABLE_XFA |
| 658 | CPDFSDK_Widget* m_CaptureWidget; |
| 659 | FX_BOOL m_bTakeOverPage; |
| 660 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | FX_BOOL m_bEnterWidget; |
| 662 | FX_BOOL m_bExitWidget; |
| 663 | FX_BOOL m_bOnWidget; |
| 664 | FX_BOOL m_bValid; |
| 665 | FX_BOOL m_bLocked; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 666 | }; |
| 667 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | template <class TYPE> |
| 669 | class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> { |
| 670 | public: |
| 671 | CGW_ArrayTemplate() {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 672 | ~CGW_ArrayTemplate() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 673 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 674 | typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 675 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) { |
| 677 | int nSize = this->GetSize(); |
| 678 | QuickSort(0, nSize - 1, bAscent, pCompare); |
| 679 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 680 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 681 | private: |
| 682 | void QuickSort(FX_UINT nStartPos, |
| 683 | FX_UINT nStopPos, |
| 684 | FX_BOOL bAscend, |
| 685 | LP_COMPARE pCompare) { |
| 686 | if (nStartPos >= nStopPos) |
| 687 | return; |
| 688 | |
| 689 | if ((nStopPos - nStartPos) == 1) { |
| 690 | TYPE Value1 = this->GetAt(nStartPos); |
| 691 | TYPE Value2 = this->GetAt(nStopPos); |
| 692 | |
| 693 | int iGreate = (*pCompare)(Value1, Value2); |
| 694 | if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { |
| 695 | this->SetAt(nStartPos, Value2); |
| 696 | this->SetAt(nStopPos, Value1); |
| 697 | } |
| 698 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 699 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 700 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; |
| 702 | FX_UINT i = nStartPos; |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 703 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 704 | TYPE Value = this->GetAt(m); |
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 | while (i < m) { |
| 707 | TYPE temp = this->GetAt(i); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 708 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | int iGreate = (*pCompare)(temp, Value); |
| 710 | if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { |
| 711 | this->InsertAt(m + 1, temp); |
| 712 | this->RemoveAt(i); |
| 713 | m--; |
| 714 | } else { |
| 715 | i++; |
| 716 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 717 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | |
| 719 | FX_UINT j = nStopPos; |
| 720 | |
| 721 | while (j > m) { |
| 722 | TYPE temp = this->GetAt(j); |
| 723 | |
| 724 | int iGreate = (*pCompare)(temp, Value); |
| 725 | if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) { |
| 726 | this->RemoveAt(j); |
| 727 | this->InsertAt(m, temp); |
| 728 | m++; |
| 729 | } else { |
| 730 | j--; |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | if (nStartPos < m) |
| 735 | QuickSort(nStartPos, m, bAscend, pCompare); |
| 736 | if (nStopPos > m) |
| 737 | QuickSort(m, nStopPos, bAscend, pCompare); |
| 738 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 739 | }; |
| 740 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 741 | #endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ |