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