OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 7 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 fxtime.wSecond = systime.wSecond; | 280 fxtime.wSecond = systime.wSecond; |
281 fxtime.wYear = systime.wYear; | 281 fxtime.wYear = systime.wYear; |
282 return fxtime; | 282 return fxtime; |
283 } | 283 } |
284 | 284 |
285 void CPDFSDK_FormFillEnvironment::OnChange() { | 285 void CPDFSDK_FormFillEnvironment::OnChange() { |
286 if (m_pInfo && m_pInfo->FFI_OnChange) | 286 if (m_pInfo && m_pInfo->FFI_OnChange) |
287 m_pInfo->FFI_OnChange(m_pInfo); | 287 m_pInfo->FFI_OnChange(m_pInfo); |
288 } | 288 } |
289 | 289 |
290 FX_BOOL CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(uint32_t nFlag) const { | 290 bool CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(uint32_t nFlag) const { |
291 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; | 291 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; |
292 } | 292 } |
293 | 293 |
294 FX_BOOL CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(uint32_t nFlag) const { | 294 bool CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(uint32_t nFlag) const { |
295 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; | 295 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; |
296 } | 296 } |
297 | 297 |
298 FX_BOOL CPDFSDK_FormFillEnvironment::IsALTKeyDown(uint32_t nFlag) const { | 298 bool CPDFSDK_FormFillEnvironment::IsALTKeyDown(uint32_t nFlag) const { |
299 return (nFlag & FWL_EVENTFLAG_AltKey) != 0; | 299 return (nFlag & FWL_EVENTFLAG_AltKey) != 0; |
300 } | 300 } |
301 | 301 |
302 FPDF_PAGE CPDFSDK_FormFillEnvironment::GetPage(FPDF_DOCUMENT document, | 302 FPDF_PAGE CPDFSDK_FormFillEnvironment::GetPage(FPDF_DOCUMENT document, |
303 int nPageIndex) { | 303 int nPageIndex) { |
304 if (m_pInfo && m_pInfo->FFI_GetPage) | 304 if (m_pInfo && m_pInfo->FFI_GetPage) |
305 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); | 305 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); |
306 return nullptr; | 306 return nullptr; |
307 } | 307 } |
308 | 308 |
309 FPDF_PAGE CPDFSDK_FormFillEnvironment::GetCurrentPage(FPDF_DOCUMENT document) { | 309 FPDF_PAGE CPDFSDK_FormFillEnvironment::GetCurrentPage(FPDF_DOCUMENT document) { |
310 if (m_pInfo && m_pInfo->FFI_GetCurrentPage) | 310 if (m_pInfo && m_pInfo->FFI_GetCurrentPage) |
311 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); | 311 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); |
312 return nullptr; | 312 return nullptr; |
313 } | 313 } |
314 | 314 |
315 void CPDFSDK_FormFillEnvironment::ExecuteNamedAction( | 315 void CPDFSDK_FormFillEnvironment::ExecuteNamedAction( |
316 const FX_CHAR* namedAction) { | 316 const FX_CHAR* namedAction) { |
317 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) | 317 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) |
318 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); | 318 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); |
319 } | 319 } |
320 | 320 |
321 void CPDFSDK_FormFillEnvironment::OnSetFieldInputFocus( | 321 void CPDFSDK_FormFillEnvironment::OnSetFieldInputFocus( |
322 FPDF_WIDESTRING focusText, | 322 FPDF_WIDESTRING focusText, |
323 FPDF_DWORD nTextLen, | 323 FPDF_DWORD nTextLen, |
324 FX_BOOL bFocus) { | 324 bool bFocus) { |
325 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) | 325 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) |
326 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); | 326 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); |
327 } | 327 } |
328 | 328 |
329 void CPDFSDK_FormFillEnvironment::DoURIAction(const FX_CHAR* bsURI) { | 329 void CPDFSDK_FormFillEnvironment::DoURIAction(const FX_CHAR* bsURI) { |
330 if (m_pInfo && m_pInfo->FFI_DoURIAction) | 330 if (m_pInfo && m_pInfo->FFI_DoURIAction) |
331 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); | 331 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); |
332 } | 332 } |
333 | 333 |
334 void CPDFSDK_FormFillEnvironment::DoGoToAction(int nPageIndex, | 334 void CPDFSDK_FormFillEnvironment::DoGoToAction(int nPageIndex, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 double right; | 410 double right; |
411 double bottom; | 411 double bottom; |
412 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); | 412 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); |
413 | 413 |
414 dstRect.left = static_cast<float>(left); | 414 dstRect.left = static_cast<float>(left); |
415 dstRect.top = static_cast<float>(top < bottom ? bottom : top); | 415 dstRect.top = static_cast<float>(top < bottom ? bottom : top); |
416 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); | 416 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); |
417 dstRect.right = static_cast<float>(right); | 417 dstRect.right = static_cast<float>(right); |
418 } | 418 } |
419 | 419 |
420 FX_BOOL CPDFSDK_FormFillEnvironment::PopupMenu(FPDF_PAGE page, | 420 bool CPDFSDK_FormFillEnvironment::PopupMenu(FPDF_PAGE page, |
421 FPDF_WIDGET hWidget, | 421 FPDF_WIDGET hWidget, |
422 int menuFlag, | 422 int menuFlag, |
423 CFX_PointF pt) { | 423 CFX_PointF pt) { |
424 return m_pInfo && m_pInfo->FFI_PopupMenu && | 424 return m_pInfo && m_pInfo->FFI_PopupMenu && |
425 m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y); | 425 m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, pt.x, pt.y); |
426 } | 426 } |
427 | 427 |
428 void CPDFSDK_FormFillEnvironment::Alert(FPDF_WIDESTRING Msg, | 428 void CPDFSDK_FormFillEnvironment::Alert(FPDF_WIDESTRING Msg, |
429 FPDF_WIDESTRING Title, | 429 FPDF_WIDESTRING Title, |
430 int Type, | 430 int Type, |
431 int Icon) { | 431 int Icon) { |
432 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { | 432 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { |
433 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type, | 433 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 (FPDF_WIDESTRING)response.str, response.len / sizeof(FPDF_WIDESTRING)); | 510 (FPDF_WIDESTRING)response.str, response.len / sizeof(FPDF_WIDESTRING)); |
511 FPDF_BStr_Clear(&response); | 511 FPDF_BStr_Clear(&response); |
512 | 512 |
513 return wsRet; | 513 return wsRet; |
514 } | 514 } |
515 | 515 |
516 FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const FX_WCHAR* wsURL, | 516 FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const FX_WCHAR* wsURL, |
517 const FX_WCHAR* wsData, | 517 const FX_WCHAR* wsData, |
518 const FX_WCHAR* wsEncode) { | 518 const FX_WCHAR* wsEncode) { |
519 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL) | 519 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL) |
520 return FALSE; | 520 return false; |
521 | 521 |
522 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); | 522 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); |
523 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); | 523 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); |
524 | 524 |
525 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); | 525 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); |
526 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); | 526 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); |
527 | 527 |
528 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); | 528 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); |
529 FPDF_WIDESTRING encode = | 529 FPDF_WIDESTRING encode = |
530 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); | 530 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 for (int i = 0; i < iCount; i++) { | 611 for (int i = 0; i < iCount; i++) { |
612 CFX_ByteString csJSName; | 612 CFX_ByteString csJSName; |
613 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); | 613 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
614 if (GetActionHander()) { | 614 if (GetActionHander()) { |
615 GetActionHander()->DoAction_JavaScript( | 615 GetActionHander()->DoAction_JavaScript( |
616 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); | 616 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); |
617 } | 617 } |
618 } | 618 } |
619 } | 619 } |
620 | 620 |
621 FX_BOOL CPDFSDK_FormFillEnvironment::ProcOpenAction() { | 621 bool CPDFSDK_FormFillEnvironment::ProcOpenAction() { |
622 if (!m_pUnderlyingDoc) | 622 if (!m_pUnderlyingDoc) |
623 return FALSE; | 623 return false; |
624 | 624 |
625 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); | 625 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); |
626 if (!pRoot) | 626 if (!pRoot) |
627 return FALSE; | 627 return false; |
628 | 628 |
629 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); | 629 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); |
630 if (!pOpenAction) | 630 if (!pOpenAction) |
631 pOpenAction = pRoot->GetArrayFor("OpenAction"); | 631 pOpenAction = pRoot->GetArrayFor("OpenAction"); |
632 | 632 |
633 if (!pOpenAction) | 633 if (!pOpenAction) |
634 return FALSE; | 634 return false; |
635 | 635 |
636 if (pOpenAction->IsArray()) | 636 if (pOpenAction->IsArray()) |
637 return TRUE; | 637 return true; |
638 | 638 |
639 if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { | 639 if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { |
640 CPDF_Action action(pDict); | 640 CPDF_Action action(pDict); |
641 if (GetActionHander()) | 641 if (GetActionHander()) |
642 GetActionHander()->DoAction_DocOpen(action, this); | 642 GetActionHander()->DoAction_DocOpen(action, this); |
643 return TRUE; | 643 return true; |
644 } | 644 } |
645 return FALSE; | 645 return false; |
646 } | 646 } |
647 | 647 |
648 void CPDFSDK_FormFillEnvironment::RemovePageView( | 648 void CPDFSDK_FormFillEnvironment::RemovePageView( |
649 UnderlyingPageType* pUnderlyingPage) { | 649 UnderlyingPageType* pUnderlyingPage) { |
650 auto it = m_pageMap.find(pUnderlyingPage); | 650 auto it = m_pageMap.find(pUnderlyingPage); |
651 if (it == m_pageMap.end()) | 651 if (it == m_pageMap.end()) |
652 return; | 652 return; |
653 | 653 |
654 CPDFSDK_PageView* pPageView = it->second.get(); | 654 CPDFSDK_PageView* pPageView = it->second.get(); |
655 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) | 655 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) |
(...skipping 28 matching lines...) Expand all Loading... |
684 | 684 |
685 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, | 685 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, |
686 CPDFSDK_Annot* pAnnot) { | 686 CPDFSDK_Annot* pAnnot) { |
687 for (const auto& it : m_pageMap) { | 687 for (const auto& it : m_pageMap) { |
688 CPDFSDK_PageView* pPageView = it.second.get(); | 688 CPDFSDK_PageView* pPageView = it.second.get(); |
689 if (pPageView != pSender) | 689 if (pPageView != pSender) |
690 pPageView->UpdateView(pAnnot); | 690 pPageView->UpdateView(pAnnot); |
691 } | 691 } |
692 } | 692 } |
693 | 693 |
694 FX_BOOL CPDFSDK_FormFillEnvironment::SetFocusAnnot( | 694 bool CPDFSDK_FormFillEnvironment::SetFocusAnnot( |
695 CPDFSDK_Annot::ObservedPtr* pAnnot) { | 695 CPDFSDK_Annot::ObservedPtr* pAnnot) { |
696 if (m_bBeingDestroyed) | 696 if (m_bBeingDestroyed) |
697 return FALSE; | 697 return false; |
698 if (m_pFocusAnnot == *pAnnot) | 698 if (m_pFocusAnnot == *pAnnot) |
699 return TRUE; | 699 return true; |
700 if (m_pFocusAnnot && !KillFocusAnnot(0)) | 700 if (m_pFocusAnnot && !KillFocusAnnot(0)) |
701 return FALSE; | 701 return false; |
702 if (!*pAnnot) | 702 if (!*pAnnot) |
703 return FALSE; | 703 return false; |
704 | 704 |
705 #ifdef PDF_ENABLE_XFA | 705 #ifdef PDF_ENABLE_XFA |
706 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); | 706 CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get()); |
707 #endif // PDF_ENABLE_XFA | 707 #endif // PDF_ENABLE_XFA |
708 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView(); | 708 CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView(); |
709 if (pPageView && pPageView->IsValid()) { | 709 if (pPageView && pPageView->IsValid()) { |
710 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); | 710 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); |
711 if (!m_pFocusAnnot) { | 711 if (!m_pFocusAnnot) { |
712 #ifdef PDF_ENABLE_XFA | 712 #ifdef PDF_ENABLE_XFA |
713 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot)) | 713 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot)) |
714 return FALSE; | 714 return false; |
715 #endif // PDF_ENABLE_XFA | 715 #endif // PDF_ENABLE_XFA |
716 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0)) | 716 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0)) |
717 return FALSE; | 717 return false; |
718 if (!m_pFocusAnnot) { | 718 if (!m_pFocusAnnot) { |
719 m_pFocusAnnot.Reset(pAnnot->Get()); | 719 m_pFocusAnnot.Reset(pAnnot->Get()); |
720 return TRUE; | 720 return true; |
721 } | 721 } |
722 } | 722 } |
723 } | 723 } |
724 return FALSE; | 724 return false; |
725 } | 725 } |
726 | 726 |
727 FX_BOOL CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) { | 727 bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) { |
728 if (m_pFocusAnnot) { | 728 if (m_pFocusAnnot) { |
729 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); | 729 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr(); |
730 CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get()); | 730 CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get()); |
731 m_pFocusAnnot.Reset(); | 731 m_pFocusAnnot.Reset(); |
732 | 732 |
733 #ifdef PDF_ENABLE_XFA | 733 #ifdef PDF_ENABLE_XFA |
734 CPDFSDK_Annot::ObservedPtr pNull; | 734 CPDFSDK_Annot::ObservedPtr pNull; |
735 if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot)) | 735 if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot)) |
736 return FALSE; | 736 return false; |
737 #endif // PDF_ENABLE_XFA | 737 #endif // PDF_ENABLE_XFA |
738 | 738 |
739 if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) { | 739 if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) { |
740 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { | 740 if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) { |
741 CPDFSDK_Widget* pWidget = | 741 CPDFSDK_Widget* pWidget = |
742 static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get()); | 742 static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get()); |
743 int nFieldType = pWidget->GetFieldType(); | 743 int nFieldType = pWidget->GetFieldType(); |
744 if (FIELDTYPE_TEXTFIELD == nFieldType || | 744 if (FIELDTYPE_TEXTFIELD == nFieldType || |
745 FIELDTYPE_COMBOBOX == nFieldType) { | 745 FIELDTYPE_COMBOBOX == nFieldType) { |
746 OnSetFieldInputFocus(nullptr, 0, FALSE); | 746 OnSetFieldInputFocus(nullptr, 0, false); |
747 } | 747 } |
748 } | 748 } |
749 if (!m_pFocusAnnot) | 749 if (!m_pFocusAnnot) |
750 return TRUE; | 750 return true; |
751 } else { | 751 } else { |
752 m_pFocusAnnot.Reset(pFocusAnnot.Get()); | 752 m_pFocusAnnot.Reset(pFocusAnnot.Get()); |
753 } | 753 } |
754 } | 754 } |
755 return FALSE; | 755 return false; |
756 } | 756 } |
757 | 757 |
758 FX_BOOL CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { | 758 bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { |
759 return !!(GetPDFDocument()->GetUserPermissions() & nFlag); | 759 return !!(GetPDFDocument()->GetUserPermissions() & nFlag); |
760 } | 760 } |
OLD | NEW |