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. |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [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 | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 7 | #include "../../public/fpdf_ext.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 8 | #include "../include/formfiller/FFL_FormFiller.h" |
| 9 | #include "../include/fpdfxfa/fpdfxfa_app.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 10 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 11 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 12 | #include "../include/fpdfxfa/fpdfxfa_util.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 13 | #include "../include/fsdk_define.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | #include "../include/fsdk_mgr.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | #include "../include/javascript/IJavaScript.h" |
| 16 | |
| 17 | #if _FX_OS_ == _FX_ANDROID_ |
| 18 | #include "time.h" |
| 19 | #else |
| 20 | #include <ctime> |
| 21 | #endif |
| 22 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 23 | class CFX_SystemHandler : public IFX_SystemHandler { |
| 24 | public: |
| 25 | CFX_SystemHandler(CPDFDoc_Environment* pEnv) : m_pEnv(pEnv), m_nCharSet(-1) {} |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 26 | ~CFX_SystemHandler() override {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | public: |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 29 | // IFX_SystemHandler |
| 30 | void InvalidateRect(FX_HWND hWnd, FX_RECT rect) override; |
| 31 | void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) override; |
| 32 | FX_BOOL IsSelectionImplemented() override; |
| 33 | CFX_WideString GetClipboardText(FX_HWND hWnd) override { return L""; } |
| 34 | FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | return FALSE; |
| 36 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 37 | void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) override {} |
| 38 | void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) override {} |
| 39 | void SetCursor(int32_t nCursorType) override; |
| 40 | FX_HMENU CreatePopupMenu() override { return NULL; } |
| 41 | FX_BOOL AppendMenuItem(FX_HMENU hMenu, |
| 42 | int32_t nIDNewItem, |
| 43 | CFX_WideString string) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | return FALSE; |
| 45 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 46 | FX_BOOL EnableMenuItem(FX_HMENU hMenu, |
| 47 | int32_t nIDItem, |
| 48 | FX_BOOL bEnabled) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | return FALSE; |
| 50 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 51 | int32_t TrackPopupMenu(FX_HMENU hMenu, |
| 52 | int32_t x, |
| 53 | int32_t y, |
| 54 | FX_HWND hParent) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | return -1; |
| 56 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 57 | void DestroyMenu(FX_HMENU hMenu) override {} |
| 58 | CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset) override; |
| 59 | FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, |
| 60 | CFX_ByteString sFontFaceName) override; |
| 61 | CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, |
| 62 | CFX_ByteString sFontFaceName, |
| 63 | uint8_t nCharset) override; |
| 64 | int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override; |
| 65 | void KillTimer(int32_t nID) override; |
| 66 | FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | return m_pEnv->FFI_IsSHIFTKeyDown(nFlag); |
| 68 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 69 | FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | return m_pEnv->FFI_IsCTRLKeyDown(nFlag); |
| 71 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 72 | FX_BOOL IsALTKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | return m_pEnv->FFI_IsALTKeyDown(nFlag); |
| 74 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 75 | FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) override { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | return m_pEnv->FFI_IsINSERTKeyDown(nFlag); |
| 77 | } |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 78 | FX_SYSTEMTIME GetLocalTime() override; |
| 79 | int32_t GetCharSet() override { return m_nCharSet; } |
| 80 | void SetCharSet(int32_t nCharSet) override { m_nCharSet = nCharSet; } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | |
| 82 | private: |
| 83 | CPDFDoc_Environment* m_pEnv; |
| 84 | int m_nCharSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | void CFX_SystemHandler::SetCursor(int32_t nCursorType) { |
| 88 | m_pEnv->FFI_SetCursor(nCursorType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { |
| 92 | // g_pFormFillApp->FFI_Invalidate(); |
| 93 | CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; |
| 94 | CPDFXFA_Page* pPage = NULL; |
| 95 | CPDFSDK_PageView* pPageView = NULL; |
| 96 | pPageView = pSDKAnnot->GetPageView(); |
| 97 | pPage = pSDKAnnot->GetPDFXFAPage(); |
| 98 | if (!pPage || !pPageView) |
| 99 | return; |
| 100 | CPDF_Matrix page2device; |
| 101 | pPageView->GetCurrentMatrix(page2device); |
| 102 | CPDF_Matrix device2page; |
| 103 | device2page.SetReverse(page2device); |
| 104 | FX_FLOAT left, top, right, bottom; |
| 105 | device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); |
| 106 | device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, |
| 107 | bottom); |
| 108 | // m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, |
| 109 | // (double*)&top); |
| 110 | // m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, |
| 111 | // (double*)&bottom); |
| 112 | CPDF_Rect rcPDF(left, bottom, right, top); |
| 113 | rcPDF.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 114 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, |
| 116 | rcPDF.bottom); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 117 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) { |
| 119 | CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; |
| 120 | if (pFFL) { |
| 121 | CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom); |
| 122 | CPDF_Point righttop = CPDF_Point(rect.right, rect.top); |
| 123 | CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); |
| 124 | CPDF_Point ptB = pFFL->PWLtoFFL(righttop); |
| 125 | CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); |
| 126 | ASSERT(pAnnot); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 127 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | ASSERT(pPage); |
| 129 | m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); |
| 130 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | FX_BOOL CFX_SystemHandler::IsSelectionImplemented() { |
| 134 | if (m_pEnv) { |
| 135 | FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); |
| 136 | if (pInfo && pInfo->FFI_OutputSelectedRect) |
| 137 | return TRUE; |
| 138 | } |
| 139 | return FALSE; |
| 140 | } |
| 141 | |
| 142 | CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset) { |
| 143 | return ""; |
| 144 | } |
| 145 | |
| 146 | FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont( |
| 147 | int32_t nCharset, |
| 148 | CFX_ByteString sFontFaceName) { |
| 149 | CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 150 | if (pFontMgr) { |
| 151 | CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper; |
| 152 | if (pFontMapper) { |
| 153 | int nSize = pFontMapper->m_InstalledTTFonts.GetSize(); |
| 154 | if (nSize == 0) { |
| 155 | pFontMapper->LoadInstalledFonts(); |
| 156 | nSize = pFontMapper->m_InstalledTTFonts.GetSize(); |
| 157 | } |
| 158 | |
| 159 | for (int i = 0; i < nSize; i++) { |
| 160 | if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName)) |
| 161 | return TRUE; |
| 162 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 163 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | return FALSE; |
| 167 | } |
| 168 | |
| 169 | static int CharSet2CP(int charset) { |
| 170 | if (charset == 128) |
| 171 | return 932; |
| 172 | if (charset == 134) |
| 173 | return 936; |
| 174 | if (charset == 129) |
| 175 | return 949; |
| 176 | if (charset == 136) |
| 177 | return 950; |
| 178 | return 0; |
| 179 | } |
| 180 | CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( |
| 181 | CPDF_Document* pDoc, |
| 182 | CFX_ByteString sFontFaceName, |
| 183 | uint8_t nCharset) { |
| 184 | if (pDoc) { |
| 185 | CFX_Font* pFXFont = new CFX_Font(); |
| 186 | pFXFont->LoadSubst(sFontFaceName, TRUE, 0, 0, 0, CharSet2CP(nCharset), |
| 187 | FALSE); |
| 188 | CPDF_Font* pFont = pDoc->AddFont(pFXFont, nCharset, FALSE); |
| 189 | delete pFXFont; |
| 190 | return pFont; |
| 191 | } |
| 192 | |
| 193 | return NULL; |
| 194 | } |
| 195 | |
| 196 | int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, |
| 197 | TimerCallback lpTimerFunc) { |
| 198 | return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); |
| 199 | } |
| 200 | void CFX_SystemHandler::KillTimer(int32_t nID) { |
| 201 | m_pEnv->FFI_KillTimer(nID); |
| 202 | } |
| 203 | |
| 204 | FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { |
| 205 | return m_pEnv->FFI_GetLocalTime(); |
| 206 | } |
| 207 | |
| 208 | CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc, |
| 209 | FPDF_FORMFILLINFO* pFFinfo) |
| 210 | : m_pAnnotHandlerMgr(NULL), |
| 211 | m_pActionHandler(NULL), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | m_pInfo(pFFinfo), |
| 213 | m_pSDKDoc(NULL), |
| 214 | m_pXFADoc(pDoc), |
| 215 | m_pIFormFiller(NULL) { |
| 216 | m_pSysHandler = new CFX_SystemHandler(this); |
| 217 | } |
| 218 | |
| 219 | CPDFDoc_Environment::~CPDFDoc_Environment() { |
| 220 | delete m_pIFormFiller; |
| 221 | m_pIFormFiller = NULL; |
| 222 | |
| 223 | CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
Tom Sepez | ed7b2b5 | 2015-09-22 08:36:17 -0700 | [diff] [blame] | 224 | if (pProvider->m_pEnvList.GetSize() == 0) |
| 225 | pProvider->SetJavaScriptInitialized(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | |
| 227 | delete m_pSysHandler; |
| 228 | m_pSysHandler = NULL; |
| 229 | |
| 230 | delete m_pAnnotHandlerMgr; |
| 231 | m_pAnnotHandlerMgr = NULL; |
| 232 | |
| 233 | delete m_pActionHandler; |
| 234 | m_pActionHandler = NULL; |
| 235 | } |
| 236 | |
| 237 | int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, |
| 238 | const FX_WCHAR* Title, |
| 239 | FX_UINT Type, |
| 240 | FX_UINT Icon) { |
| 241 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { |
| 242 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 243 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 244 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 245 | FPDF_WIDESTRING pTitle = |
| 246 | (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); |
| 247 | int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, |
| 248 | pTitle, Type, Icon); |
| 249 | bsMsg.ReleaseBuffer(); |
| 250 | bsTitle.ReleaseBuffer(); |
| 251 | return ret; |
| 252 | } |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, |
| 257 | const FX_WCHAR* Title, |
| 258 | const FX_WCHAR* Default, |
| 259 | const FX_WCHAR* cLabel, |
| 260 | FPDF_BOOL bPassword, |
| 261 | void* response, |
| 262 | int length) { |
| 263 | if (m_pInfo && m_pInfo->m_pJsPlatform && |
| 264 | m_pInfo->m_pJsPlatform->app_response) { |
| 265 | CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); |
| 266 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 267 | CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); |
| 268 | CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); |
| 269 | FPDF_WIDESTRING pQuestion = |
| 270 | (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength()); |
| 271 | FPDF_WIDESTRING pTitle = |
| 272 | (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); |
| 273 | FPDF_WIDESTRING pDefault = |
| 274 | (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength()); |
| 275 | FPDF_WIDESTRING pLabel = |
| 276 | (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength()); |
| 277 | int ret = m_pInfo->m_pJsPlatform->app_response( |
| 278 | m_pInfo->m_pJsPlatform, pQuestion, pTitle, pDefault, pLabel, bPassword, |
| 279 | response, length); |
| 280 | bsQuestion.ReleaseBuffer(); |
| 281 | bsTitle.ReleaseBuffer(); |
| 282 | bsDefault.ReleaseBuffer(); |
| 283 | bsLabel.ReleaseBuffer(); |
| 284 | return ret; |
| 285 | } |
| 286 | return -1; |
| 287 | } |
| 288 | |
| 289 | CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { |
| 290 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 291 | !m_pInfo->m_pJsPlatform->Field_browse) { |
| 292 | return L""; |
| 293 | } |
| 294 | |
| 295 | const int nRequiredLen = |
| 296 | m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, nullptr, 0); |
| 297 | if (nRequiredLen <= 0) |
| 298 | return L""; |
| 299 | |
| 300 | nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 301 | memset(pBuff.get(), 0, nRequiredLen); |
| 302 | const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( |
| 303 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 304 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 305 | return L""; |
| 306 | |
| 307 | CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 308 | CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 309 | return wsRet; |
| 310 | } |
| 311 | |
| 312 | CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { |
| 313 | if (!m_pInfo || !m_pInfo->m_pJsPlatform || |
| 314 | !m_pInfo->m_pJsPlatform->Doc_getFilePath) { |
| 315 | return L""; |
| 316 | } |
| 317 | |
| 318 | const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 319 | m_pInfo->m_pJsPlatform, nullptr, 0); |
| 320 | if (nRequiredLen <= 0) |
| 321 | return L""; |
| 322 | |
| 323 | nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 324 | memset(pBuff.get(), 0, nRequiredLen); |
| 325 | const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 326 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 327 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 328 | return L""; |
| 329 | |
| 330 | CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 331 | CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 332 | return wsRet; |
| 333 | } |
| 334 | |
| 335 | void CPDFDoc_Environment::JS_docSubmitForm(void* formData, |
| 336 | int length, |
| 337 | const FX_WCHAR* URL) { |
| 338 | if (m_pInfo && m_pInfo->m_pJsPlatform && |
| 339 | m_pInfo->m_pJsPlatform->Doc_submitForm) { |
| 340 | CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); |
| 341 | FPDF_WIDESTRING pDestination = |
| 342 | (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength()); |
| 343 | m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, |
| 344 | length, pDestination); |
| 345 | bsDestination.ReleaseBuffer(); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void CPDFDoc_Environment::JS_docmailForm(void* mailData, |
| 350 | int length, |
| 351 | FPDF_BOOL bUI, |
| 352 | const FX_WCHAR* To, |
| 353 | const FX_WCHAR* Subject, |
| 354 | const FX_WCHAR* CC, |
| 355 | const FX_WCHAR* BCC, |
| 356 | const FX_WCHAR* Msg) { |
| 357 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) { |
| 358 | CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); |
| 359 | CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode(); |
| 360 | CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); |
| 361 | CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); |
| 362 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 363 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); |
| 364 | FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); |
| 365 | FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); |
| 366 | FPDF_WIDESTRING pSubject = |
| 367 | (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); |
| 368 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 369 | m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, |
| 370 | bUI, pTo, pSubject, pCC, pBcc, pMsg); |
| 371 | bsTo.ReleaseBuffer(); |
| 372 | bsCC.ReleaseBuffer(); |
| 373 | bsBcc.ReleaseBuffer(); |
| 374 | bsSubject.ReleaseBuffer(); |
| 375 | bsMsg.ReleaseBuffer(); |
| 376 | } |
| 377 | } |
| 378 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 379 | IJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | if (!IsJSInitiated()) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 381 | return NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | if (!m_pJSRuntime) |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 383 | m_pJSRuntime.reset(IJS_Runtime::Create(this)); |
Tom Sepez | 854a7f6 | 2015-09-21 17:07:49 -0700 | [diff] [blame] | 384 | return m_pJSRuntime.get(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { |
| 388 | if (!m_pAnnotHandlerMgr) |
| 389 | m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); |
| 390 | return m_pAnnotHandlerMgr; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() { |
| 394 | if (!m_pActionHandler) |
Tom Sepez | 3b5f124 | 2015-09-01 14:06:55 -0700 | [diff] [blame] | 395 | m_pActionHandler = new CPDFSDK_ActionHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 396 | return m_pActionHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 399 | CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() { |
| 400 | if (!m_pIFormFiller) |
| 401 | m_pIFormFiller = new CFFL_IFormFiller(this); |
| 402 | return m_pIFormFiller; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 405 | CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc, |
| 406 | CPDFDoc_Environment* pEnv) |
| 407 | : m_pDoc(pDoc), |
| 408 | m_pInterForm(nullptr), |
| 409 | m_pFocusAnnot(nullptr), |
| 410 | m_pEnv(pEnv), |
| 411 | m_pOccontent(nullptr), |
| 412 | m_bChangeMask(FALSE) {} |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 413 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | CPDFSDK_Document::~CPDFSDK_Document() { |
| 415 | for (auto& it : m_pageMap) |
| 416 | delete it.second; |
| 417 | m_pageMap.clear(); |
| 418 | |
| 419 | delete m_pInterForm; |
| 420 | m_pInterForm = nullptr; |
| 421 | |
| 422 | delete m_pOccontent; |
| 423 | m_pOccontent = nullptr; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 424 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 425 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 426 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, |
| 427 | FX_BOOL ReNew) { |
| 428 | auto it = m_pageMap.find(pPDFXFAPage); |
| 429 | if (it != m_pageMap.end()) |
| 430 | return it->second; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 431 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | if (!ReNew) |
| 433 | return nullptr; |
| 434 | |
| 435 | CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFXFAPage); |
| 436 | m_pageMap[pPDFXFAPage] = pPageView; |
| 437 | // Delay to load all the annotations, to avoid endless loop. |
| 438 | pPageView->LoadFXAnnots(); |
| 439 | return pPageView; |
| 440 | } |
| 441 | |
| 442 | CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() { |
| 443 | CPDFXFA_Page* pPage = (CPDFXFA_Page*)m_pEnv->FFI_GetCurrentPage(m_pDoc); |
| 444 | return pPage ? GetPageView(pPage, TRUE) : nullptr; |
| 445 | } |
| 446 | |
| 447 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { |
| 448 | CPDFXFA_Page* pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); |
| 449 | if (!pTempPage) |
| 450 | return nullptr; |
| 451 | |
| 452 | auto it = m_pageMap.find(pTempPage); |
| 453 | return it->second; |
| 454 | } |
| 455 | |
| 456 | void CPDFSDK_Document::ProcJavascriptFun() { |
| 457 | CPDFXFA_Document* pPDFDoc = GetDocument(); |
| 458 | CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc()); |
| 459 | int iCount = docJS.CountJSActions(); |
| 460 | if (iCount < 1) |
| 461 | return; |
| 462 | for (int i = 0; i < iCount; i++) { |
| 463 | CFX_ByteString csJSName; |
| 464 | CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
| 465 | if (m_pEnv->GetActionHander()) |
| 466 | m_pEnv->GetActionHander()->DoAction_JavaScript( |
| 467 | jsAction, CFX_WideString::FromLocal(csJSName), this); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | FX_BOOL CPDFSDK_Document::ProcOpenAction() { |
| 472 | if (!m_pDoc) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 473 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | |
| 475 | CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot(); |
| 476 | if (!pRoot) |
| 477 | return FALSE; |
| 478 | |
| 479 | CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); |
| 480 | if (!pOpenAction) |
| 481 | pOpenAction = pRoot->GetArray("OpenAction"); |
| 482 | |
| 483 | if (!pOpenAction) |
| 484 | return FALSE; |
| 485 | |
| 486 | if (pOpenAction->GetType() == PDFOBJ_ARRAY) |
| 487 | return TRUE; |
| 488 | |
| 489 | if (pOpenAction->GetType() == PDFOBJ_DICTIONARY) { |
| 490 | CPDF_Dictionary* pDict = (CPDF_Dictionary*)pOpenAction; |
| 491 | CPDF_Action action(pDict); |
| 492 | if (m_pEnv->GetActionHander()) |
| 493 | m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); |
| 494 | return TRUE; |
| 495 | } |
| 496 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | CPDF_OCContext* CPDFSDK_Document::GetOCContext() { |
| 500 | if (!m_pOccontent) |
| 501 | m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc()); |
| 502 | return m_pOccontent; |
| 503 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 504 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 505 | void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) { |
| 506 | auto it = m_pageMap.find(pPDFXFAPage); |
| 507 | if (it == m_pageMap.end()) |
| 508 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 509 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 510 | CPDFSDK_PageView* pPageView = it->second; |
| 511 | if (pPageView->IsLocked()) |
| 512 | return; |
| 513 | |
| 514 | delete pPageView; |
| 515 | m_pageMap.erase(it); |
| 516 | } |
| 517 | |
| 518 | CPDFXFA_Page* CPDFSDK_Document::GetPage(int nIndex) { |
| 519 | CPDFXFA_Page* pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); |
| 520 | if (!pTempPage) |
| 521 | return NULL; |
| 522 | return pTempPage; |
| 523 | } |
| 524 | |
| 525 | CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { |
| 526 | if (!m_pInterForm) |
| 527 | m_pInterForm = new CPDFSDK_InterForm(this); |
| 528 | return m_pInterForm; |
| 529 | } |
| 530 | |
| 531 | void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, |
| 532 | CPDFSDK_Annot* pAnnot) { |
| 533 | for (const auto& it : m_pageMap) { |
| 534 | CPDFSDK_PageView* pPageView = it.second; |
| 535 | if (pPageView != pSender) { |
| 536 | pPageView->UpdateView(pAnnot); |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() { |
| 542 | return m_pFocusAnnot; |
| 543 | } |
| 544 | |
| 545 | FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { |
| 546 | if (m_pFocusAnnot == pAnnot) |
| 547 | return TRUE; |
| 548 | |
| 549 | CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
| 550 | |
| 551 | if (m_pFocusAnnot) { |
| 552 | if (!KillFocusAnnot(nFlag)) |
| 553 | return FALSE; |
| 554 | } |
| 555 | CPDFSDK_PageView* pPageView = NULL; |
| 556 | if (pAnnot) |
| 557 | pPageView = pAnnot->GetPageView(); |
| 558 | if (pAnnot && pPageView->IsValid()) { |
| 559 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
| 560 | |
| 561 | if (pAnnotHandler && !m_pFocusAnnot) { |
| 562 | if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 563 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 564 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) |
| 566 | return FALSE; |
| 567 | if (!m_pFocusAnnot) { |
| 568 | m_pFocusAnnot = pAnnot; |
| 569 | return TRUE; |
| 570 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 571 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | } |
| 573 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 576 | FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { |
| 577 | if (m_pFocusAnnot) { |
| 578 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
| 579 | if (pAnnotHandler) { |
| 580 | CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
| 581 | m_pFocusAnnot = NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 582 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 583 | if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot)) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 584 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 585 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 586 | if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
| 587 | if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) { |
| 588 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
| 589 | int nFieldType = pWidget->GetFieldType(); |
| 590 | if (FIELDTYPE_TEXTFIELD == nFieldType || |
| 591 | FIELDTYPE_COMBOBOX == nFieldType) |
| 592 | m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); |
| 593 | } |
| 594 | |
| 595 | if (!m_pFocusAnnot) |
| 596 | return TRUE; |
| 597 | } else { |
| 598 | m_pFocusAnnot = pFocusAnnot; |
| 599 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 600 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | } |
| 602 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 603 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 604 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount) { |
| 606 | if (nStart < 0 || nStart >= GetPageCount() || nCount <= 0) { |
| 607 | return FALSE; |
| 608 | } |
| 609 | |
| 610 | CPDFXFA_Page* pTempPage = NULL; |
| 611 | for (int i = nCount - 1; i >= 0; i--) { |
| 612 | pTempPage = GetPage(nStart + i); |
| 613 | if (pTempPage != NULL) { |
| 614 | ReMovePageView(pTempPage); |
| 615 | } |
| 616 | } |
| 617 | return TRUE; |
| 618 | } |
| 619 | |
| 620 | void CPDFSDK_Document::OnCloseDocument() { |
| 621 | KillFocusAnnot(); |
| 622 | } |
| 623 | |
| 624 | FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { |
| 625 | FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions(); |
| 626 | return dwPermissions & nFlag; |
| 627 | } |
| 628 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 629 | IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | ASSERT(m_pEnv != NULL); |
| 631 | return m_pEnv->GetJSRuntime(); |
| 632 | } |
| 633 | |
| 634 | CFX_WideString CPDFSDK_Document::GetPath() { |
| 635 | ASSERT(m_pEnv != NULL); |
| 636 | return m_pEnv->JS_docGetFilePath(); |
| 637 | } |
| 638 | |
| 639 | CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
| 640 | CPDFXFA_Page* page) |
| 641 | : m_page(page), m_pSDKDoc(pSDKDoc) { |
| 642 | CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
| 643 | if (pInterForm) { |
| 644 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 645 | if (page->GetPDFPage()) |
| 646 | pPDFInterForm->FixPageFields(page->GetPDFPage()); |
| 647 | } |
| 648 | m_fxAnnotArray.RemoveAll(); |
| 649 | |
| 650 | m_bEnterWidget = FALSE; |
| 651 | m_bExitWidget = FALSE; |
| 652 | m_bOnWidget = FALSE; |
| 653 | m_CaptureWidget = NULL; |
| 654 | m_bValid = FALSE; |
| 655 | m_bLocked = FALSE; |
| 656 | m_pAnnotList = NULL; |
| 657 | } |
| 658 | |
| 659 | CPDFSDK_PageView::~CPDFSDK_PageView() { |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 660 | // if there is a focused annot on the page, we should kill the focus first. |
| 661 | if (CPDFSDK_Annot* focusedAnnot = m_pSDKDoc->GetFocusAnnot()) { |
| 662 | for (int i = 0, count = m_fxAnnotArray.GetSize(); i < count; i++) { |
| 663 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 664 | if (pAnnot == focusedAnnot) { |
| 665 | KillFocusAnnot(); |
| 666 | break; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 671 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | 396e872 | 2015-09-09 10:16:08 -0700 | [diff] [blame] | 672 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 673 | ASSERT(pAnnotHandlerMgr); |
| 674 | for (int i = 0, count = m_fxAnnotArray.GetSize(); i < count; i++) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
| 677 | } |
| 678 | m_fxAnnotArray.RemoveAll(); |
| 679 | |
| 680 | delete m_pAnnotList; |
| 681 | m_pAnnotList = NULL; |
| 682 | } |
| 683 | |
| 684 | void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 685 | CPDF_Matrix* pUser2Device, |
| 686 | CPDF_RenderOptions* pOptions, |
| 687 | FX_RECT* pClip) { |
| 688 | m_curMatrix = *pUser2Device; |
| 689 | // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, |
| 690 | // pOptions); |
| 691 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 692 | CPDFXFA_Page* pPage = GetPDFXFAPage(); |
| 693 | |
| 694 | if (pPage == NULL) |
| 695 | return; |
| 696 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame^] | 697 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { |
| 699 | CFX_Graphics gs; |
| 700 | gs.Create(pDevice); |
| 701 | if (pClip) { |
| 702 | CFX_RectF rectClip; |
| 703 | rectClip.Set(static_cast<FX_FLOAT>(pClip->left), |
| 704 | static_cast<FX_FLOAT>(pClip->top), |
| 705 | static_cast<FX_FLOAT>(pClip->Width()), |
| 706 | static_cast<FX_FLOAT>(pClip->Height())); |
| 707 | gs.SetClipRect(rectClip); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 708 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); |
| 710 | if (!pRenderContext) |
| 711 | return; |
| 712 | CXFA_RenderOptions renderOptions; |
| 713 | renderOptions.m_bHighlight = TRUE; |
| 714 | pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, |
| 715 | renderOptions); |
| 716 | pRenderContext->DoRender(); |
| 717 | pRenderContext->StopRender(); |
| 718 | pRenderContext->Release(); |
| 719 | return; |
| 720 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame^] | 721 | #endif // PDF_ENABLE_XFA |
| 722 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | // for pdf/static xfa. |
| 724 | CPDFSDK_AnnotIterator annotIterator(this, TRUE); |
| 725 | CPDFSDK_Annot* pSDKAnnot = NULL; |
| 726 | int index = -1; |
| 727 | pSDKAnnot = annotIterator.Next(index); |
| 728 | while (pSDKAnnot) { |
| 729 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 730 | ASSERT(pAnnotHandlerMgr); |
| 731 | pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
| 732 | pSDKAnnot = annotIterator.Next(index); |
| 733 | } |
| 734 | } |
| 735 | CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
| 736 | FX_FLOAT pageY) { |
| 737 | int nCount = m_pAnnotList->Count(); |
| 738 | for (int i = 0; i < nCount; i++) { |
| 739 | CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
| 740 | CFX_FloatRect annotRect; |
| 741 | pAnnot->GetRect(annotRect); |
| 742 | if (annotRect.Contains(pageX, pageY)) |
| 743 | return pAnnot; |
| 744 | } |
| 745 | return NULL; |
| 746 | } |
| 747 | |
| 748 | CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, |
| 749 | FX_FLOAT pageY) { |
| 750 | int nCount = m_pAnnotList->Count(); |
| 751 | for (int i = 0; i < nCount; i++) { |
| 752 | CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
| 753 | if (pAnnot->GetSubType() == "Widget") { |
| 754 | CFX_FloatRect annotRect; |
| 755 | pAnnot->GetRect(annotRect); |
| 756 | if (annotRect.Contains(pageX, pageY)) |
| 757 | return pAnnot; |
| 758 | } |
| 759 | } |
| 760 | return NULL; |
| 761 | } |
| 762 | |
| 763 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, |
| 764 | FX_FLOAT pageY) { |
| 765 | CPDFSDK_AnnotIterator annotIterator(this, FALSE); |
| 766 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 767 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
| 768 | CPDFSDK_Annot* pSDKAnnot = NULL; |
| 769 | int index = -1; |
| 770 | pSDKAnnot = annotIterator.Next(index); |
| 771 | while (pSDKAnnot) { |
| 772 | CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 773 | if (rc.Contains(pageX, pageY)) |
| 774 | return pSDKAnnot; |
| 775 | pSDKAnnot = annotIterator.Next(index); |
| 776 | } |
| 777 | |
| 778 | return NULL; |
| 779 | } |
| 780 | |
| 781 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, |
| 782 | FX_FLOAT pageY) { |
| 783 | CPDFSDK_AnnotIterator annotIterator(this, FALSE); |
| 784 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 785 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
| 786 | CPDFSDK_Annot* pSDKAnnot = NULL; |
| 787 | int index = -1; |
| 788 | pSDKAnnot = annotIterator.Next(index); |
| 789 | while (pSDKAnnot) { |
| 790 | if (pSDKAnnot->GetType() == "Widget" || |
| 791 | pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME) { |
| 792 | pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 793 | CPDF_Point point(pageX, pageY); |
| 794 | if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
| 795 | return pSDKAnnot; |
| 796 | } |
| 797 | pSDKAnnot = annotIterator.Next(index); |
| 798 | } |
| 799 | |
| 800 | return NULL; |
| 801 | } |
| 802 | |
| 803 | FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) { |
| 804 | CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict(); |
| 805 | if (pAnnotDic) |
| 806 | return pAnnotDic->KeyExist("AS"); |
| 807 | return FALSE; |
| 808 | } |
| 809 | |
| 810 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot* pPDFAnnot) { |
| 811 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 812 | ASSERT(pEnv); |
| 813 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
| 814 | |
| 815 | CPDFSDK_Annot* pSDKAnnot = NULL; |
| 816 | |
| 817 | if (pAnnotHandler) { |
| 818 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 819 | } |
| 820 | if (!pSDKAnnot) |
| 821 | return NULL; |
| 822 | |
| 823 | m_fxAnnotArray.Add(pSDKAnnot); |
| 824 | |
| 825 | if (pAnnotHandler) { |
| 826 | pAnnotHandler->Annot_OnCreate(pSDKAnnot); |
| 827 | } |
| 828 | |
| 829 | return pSDKAnnot; |
| 830 | } |
| 831 | |
| 832 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { |
| 833 | if (!pPDFAnnot) |
| 834 | return NULL; |
| 835 | |
| 836 | CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 837 | if (pSDKAnnot) |
| 838 | return pSDKAnnot; |
| 839 | |
| 840 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 841 | ASSERT(pEnv); |
| 842 | CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
| 843 | |
| 844 | pSDKAnnot = NULL; |
| 845 | |
| 846 | if (pAnnotHandler) { |
| 847 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 848 | } |
| 849 | if (!pSDKAnnot) |
| 850 | return NULL; |
| 851 | |
| 852 | m_fxAnnotArray.Add(pSDKAnnot); |
| 853 | |
| 854 | return pSDKAnnot; |
| 855 | } |
| 856 | |
| 857 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { |
| 858 | return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; |
| 859 | } |
| 860 | |
| 861 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, |
| 862 | CPDF_Dictionary* pDict) { |
| 863 | return NULL; |
| 864 | } |
| 865 | |
| 866 | FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
| 867 | if (!pAnnot) |
| 868 | return FALSE; |
| 869 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 870 | if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
| 871 | pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA)) |
| 872 | return FALSE; |
| 873 | |
| 874 | int index = m_fxAnnotArray.Find(pAnnot); |
| 875 | m_fxAnnotArray.RemoveAt(index); |
| 876 | if (m_CaptureWidget == pAnnot) |
| 877 | m_CaptureWidget = NULL; |
| 878 | |
| 879 | return TRUE; |
| 880 | } |
| 881 | |
| 882 | CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
| 883 | if (m_page) { |
| 884 | return m_page->GetDocument()->GetPDFDoc(); |
| 885 | } |
| 886 | return NULL; |
| 887 | } |
| 888 | |
| 889 | CPDF_Page* CPDFSDK_PageView::GetPDFPage() { |
| 890 | if (m_page) { |
| 891 | return m_page->GetPDFPage(); |
| 892 | } |
| 893 | |
| 894 | return NULL; |
| 895 | } |
| 896 | |
| 897 | int CPDFSDK_PageView::CountAnnots() { |
| 898 | return m_fxAnnotArray.GetSize(); |
| 899 | } |
| 900 | |
| 901 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) { |
| 902 | int nCount = m_fxAnnotArray.GetSize(); |
| 903 | if (nIndex < 0 || nIndex >= nCount) { |
| 904 | return NULL; |
| 905 | } |
| 906 | |
| 907 | return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex); |
| 908 | } |
| 909 | |
| 910 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
| 911 | int nCount = m_fxAnnotArray.GetSize(); |
| 912 | for (int i = 0; i < nCount; i++) { |
| 913 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 914 | if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict()) |
| 915 | return pAnnot; |
| 916 | } |
| 917 | return NULL; |
| 918 | } |
| 919 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { |
| 920 | if (hWidget == NULL) |
| 921 | return NULL; |
| 922 | int annotCount = m_fxAnnotArray.GetSize(); |
| 923 | |
| 924 | for (int i = 0; i < annotCount; i++) { |
| 925 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 926 | if (pAnnot->GetXFAWidget() == hWidget) |
| 927 | return pAnnot; |
| 928 | } |
| 929 | return NULL; |
| 930 | } |
| 931 | |
| 932 | FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, |
| 933 | FX_UINT nFlag) { |
| 934 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 935 | ASSERT(pEnv); |
| 936 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 937 | if (!pFXAnnot) { |
| 938 | KillFocusAnnot(nFlag); |
| 939 | } else { |
| 940 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 941 | ASSERT(pAnnotHandlerMgr); |
| 942 | |
| 943 | FX_BOOL bRet = |
| 944 | pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); |
| 945 | if (bRet) { |
| 946 | SetFocusAnnot(pFXAnnot); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 947 | } |
| 948 | return bRet; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 949 | } |
| 950 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 953 | FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, |
| 954 | FX_UINT nFlag) { |
| 955 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 956 | ASSERT(pEnv); |
| 957 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 958 | ASSERT(pAnnotHandlerMgr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 959 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 961 | |
| 962 | if (pFXAnnot == NULL) |
| 963 | return FALSE; |
| 964 | |
| 965 | FX_BOOL bRet = |
| 966 | pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); |
| 967 | if (bRet) { |
| 968 | SetFocusAnnot(pFXAnnot); |
| 969 | } |
| 970 | return TRUE; |
| 971 | } |
| 972 | |
| 973 | FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 974 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 975 | ASSERT(pEnv); |
| 976 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 977 | ASSERT(pAnnotHandlerMgr); |
| 978 | |
| 979 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 980 | |
| 981 | if (pFXAnnot == NULL) |
| 982 | return FALSE; |
| 983 | |
| 984 | FX_BOOL bRet = |
| 985 | pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); |
| 986 | if (bRet) { |
| 987 | SetFocusAnnot(pFXAnnot); |
| 988 | } |
| 989 | return TRUE; |
| 990 | } |
| 991 | |
| 992 | FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 993 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 994 | ASSERT(pEnv); |
| 995 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 996 | ASSERT(pAnnotHandlerMgr); |
| 997 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 998 | CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); |
| 999 | FX_BOOL bRet = FALSE; |
| 1000 | if (pFocusAnnot && pFocusAnnot != pFXAnnot) { |
| 1001 | // Last focus Annot gets a chance to handle the event. |
| 1002 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); |
| 1003 | } |
| 1004 | if (pFXAnnot && !bRet) { |
| 1005 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag, point); |
| 1006 | return bRet; |
| 1007 | } |
| 1008 | return bRet; |
| 1009 | } |
| 1010 | |
| 1011 | FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point& point, int nFlag) { |
| 1012 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1013 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1014 | ASSERT(pAnnotHandlerMgr); |
| 1015 | if (CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
| 1016 | if (m_CaptureWidget && m_CaptureWidget != pFXAnnot) { |
| 1017 | m_bExitWidget = TRUE; |
| 1018 | m_bEnterWidget = FALSE; |
| 1019 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 1020 | } |
| 1021 | m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot; |
| 1022 | m_bOnWidget = TRUE; |
| 1023 | if (!m_bEnterWidget) { |
| 1024 | m_bEnterWidget = TRUE; |
| 1025 | m_bExitWidget = FALSE; |
| 1026 | pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot, nFlag); |
| 1027 | } |
| 1028 | pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); |
| 1029 | return TRUE; |
| 1030 | } |
| 1031 | if (m_bOnWidget) { |
| 1032 | m_bOnWidget = FALSE; |
| 1033 | m_bExitWidget = TRUE; |
| 1034 | m_bEnterWidget = FALSE; |
| 1035 | if (m_CaptureWidget) { |
| 1036 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 1037 | m_CaptureWidget = NULL; |
| 1038 | } |
| 1039 | } |
| 1040 | return FALSE; |
| 1041 | } |
| 1042 | |
| 1043 | FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, |
| 1044 | double deltaY, |
| 1045 | const CPDF_Point& point, |
| 1046 | int nFlag) { |
| 1047 | if (CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1048 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1049 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1050 | ASSERT(pAnnotHandlerMgr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1051 | return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, |
| 1052 | (int)deltaY, point); |
| 1053 | } |
| 1054 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1057 | FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) { |
| 1058 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1059 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1060 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1061 | ASSERT(pAnnotHandlerMgr); |
| 1062 | return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
| 1063 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1064 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1065 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1068 | FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { |
| 1069 | if (CPDFSDK_Annot* pAnnot = GetFocusAnnot()) { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1070 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1071 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1072 | ASSERT(pAnnotHandlerMgr); |
| 1073 | return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 1074 | } |
| 1075 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1078 | FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1079 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1082 | void CPDFSDK_PageView::LoadFXAnnots() { |
| 1083 | ASSERT(m_page != NULL); |
| 1084 | |
| 1085 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1086 | ASSERT(pEnv != NULL); |
| 1087 | |
| 1088 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1089 | ASSERT(pAnnotHandlerMgr != NULL); |
| 1090 | |
| 1091 | SetLock(TRUE); |
| 1092 | m_page->AddRef(); |
| 1093 | if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { |
| 1094 | IXFA_PageView* pageView = NULL; |
| 1095 | pageView = m_page->GetXFAPageView(); |
| 1096 | ASSERT(pageView != NULL); |
| 1097 | |
| 1098 | IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator( |
| 1099 | XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible | |
| 1100 | XFA_WIDGETFILTER_Viewable | |
| 1101 | XFA_WIDGETFILTER_AllType); |
| 1102 | if (!pWidgetHander) { |
| 1103 | m_page->Release(); |
| 1104 | SetLock(FALSE); |
| 1105 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1106 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | |
| 1108 | IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext(); |
| 1109 | while (pXFAAnnot) { |
| 1110 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
| 1111 | if (!pAnnot) { |
| 1112 | pXFAAnnot = pWidgetHander->MoveToNext(); |
| 1113 | continue; |
| 1114 | } |
| 1115 | m_fxAnnotArray.Add(pAnnot); |
| 1116 | |
| 1117 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1118 | |
| 1119 | pXFAAnnot = pWidgetHander->MoveToNext(); |
| 1120 | } |
| 1121 | |
| 1122 | pWidgetHander->Release(); |
| 1123 | } else { |
| 1124 | CPDF_Page* pPage = m_page->GetPDFPage(); |
| 1125 | ASSERT(pPage != NULL); |
| 1126 | |
| 1127 | FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 1128 | // Disable the default AP construction. |
| 1129 | CPDF_InterForm::EnableUpdateAP(FALSE); |
| 1130 | m_pAnnotList = new CPDF_AnnotList(pPage); |
| 1131 | CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
| 1132 | |
| 1133 | int nCount = m_pAnnotList->Count(); |
| 1134 | for (int i = 0; i < nCount; i++) { |
| 1135 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 1136 | CPDF_Document* pDoc = GetPDFDocument(); |
| 1137 | |
| 1138 | CheckUnSupportAnnot(pDoc, pPDFAnnot); |
| 1139 | |
| 1140 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 1141 | if (!pAnnot) |
| 1142 | continue; |
| 1143 | m_fxAnnotArray.Add(pAnnot); |
| 1144 | |
| 1145 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1146 | } |
| 1147 | } |
| 1148 | m_page->Release(); |
| 1149 | SetLock(FALSE); |
| 1150 | } |
| 1151 | |
| 1152 | void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { |
| 1153 | for (int i = 0; i < rects.GetSize(); i++) { |
| 1154 | CPDF_Rect rc = rects.GetAt(i); |
| 1155 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1156 | pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
| 1161 | CPDF_Rect rcWindow = pAnnot->GetRect(); |
| 1162 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1163 | pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, |
| 1164 | rcWindow.bottom); |
| 1165 | } |
| 1166 | |
| 1167 | int CPDFSDK_PageView::GetPageIndex() { |
| 1168 | if (m_page) { |
| 1169 | CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
| 1170 | CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); |
| 1171 | if (pDoc && pDic) { |
| 1172 | return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); |
| 1173 | } |
| 1174 | } |
| 1175 | return -1; |
| 1176 | } |
| 1177 | |
| 1178 | FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) { |
| 1179 | if (p == NULL) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1180 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1181 | int iCount = m_pAnnotList->Count(); |
| 1182 | for (int i = 0; i < iCount; i++) { |
| 1183 | if (m_pAnnotList->GetAt(i) == p) |
| 1184 | return TRUE; |
| 1185 | } |
| 1186 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1189 | CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
| 1190 | CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
| 1191 | if (!pFocusAnnot) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1192 | return NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1193 | |
| 1194 | for (int i = 0; i < m_fxAnnotArray.GetSize(); i++) { |
| 1195 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 1196 | if (pAnnot == pFocusAnnot) |
| 1197 | return pAnnot; |
| 1198 | } |
| 1199 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1200 | } |