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