| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/include/fsdk_mgr.h" | 7 #include "fpdfsdk/include/fsdk_mgr.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 if (m_page) { | 713 if (m_page) { |
| 714 #ifdef PDF_ENABLE_XFA | 714 #ifdef PDF_ENABLE_XFA |
| 715 return m_page->GetDocument()->GetPDFDoc(); | 715 return m_page->GetDocument()->GetPDFDoc(); |
| 716 #else // PDF_ENABLE_XFA | 716 #else // PDF_ENABLE_XFA |
| 717 return m_page->m_pDocument; | 717 return m_page->m_pDocument; |
| 718 #endif // PDF_ENABLE_XFA | 718 #endif // PDF_ENABLE_XFA |
| 719 } | 719 } |
| 720 return nullptr; | 720 return nullptr; |
| 721 } | 721 } |
| 722 | 722 |
| 723 CPDF_Page* CPDFSDK_PageView::GetPDFPage() const { |
| 723 #ifdef PDF_ENABLE_XFA | 724 #ifdef PDF_ENABLE_XFA |
| 724 CPDF_Page* CPDFSDK_PageView::GetPDFPage() { | 725 return m_page ? m_page->GetPDFPage() : nullptr; |
| 725 if (m_page) { | 726 #else // PDF_ENABLE_XFA |
| 726 return m_page->GetPDFPage(); | 727 return m_page; |
| 727 } | 728 #endif // PDF_ENABLE_XFA |
| 728 return nullptr; | |
| 729 } | 729 } |
| 730 #endif // PDF_ENABLE_XFA | |
| 731 | 730 |
| 732 size_t CPDFSDK_PageView::CountAnnots() const { | 731 size_t CPDFSDK_PageView::CountAnnots() const { |
| 733 return m_fxAnnotArray.size(); | 732 return m_fxAnnotArray.size(); |
| 734 } | 733 } |
| 735 | 734 |
| 736 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { | 735 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { |
| 737 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; | 736 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; |
| 738 } | 737 } |
| 739 | 738 |
| 740 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { | 739 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 781 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 783 ASSERT(pEnv); | 782 ASSERT(pEnv); |
| 784 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 783 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 785 ASSERT(pAnnotHandlerMgr); | 784 ASSERT(pAnnotHandlerMgr); |
| 786 | 785 |
| 787 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 786 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 788 | 787 |
| 789 if (!pFXAnnot) | 788 if (!pFXAnnot) |
| 790 return FALSE; | 789 return FALSE; |
| 791 | 790 |
| 792 FX_BOOL bRet = | 791 if (pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point)) |
| 793 pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); | |
| 794 if (bRet) { | |
| 795 SetFocusAnnot(pFXAnnot); | 792 SetFocusAnnot(pFXAnnot); |
| 796 } | 793 |
| 797 return TRUE; | 794 return TRUE; |
| 798 } | 795 } |
| 799 | 796 |
| 800 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, | 797 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CFX_FloatPoint& point, |
| 801 FX_UINT nFlag) { | 798 FX_UINT nFlag) { |
| 802 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 799 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 803 ASSERT(pEnv); | 800 ASSERT(pEnv); |
| 804 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 801 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 805 | 802 |
| 806 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 803 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 807 | 804 |
| 808 if (!pFXAnnot) | 805 if (!pFXAnnot) |
| 809 return FALSE; | 806 return FALSE; |
| 810 | 807 |
| 811 FX_BOOL bRet = | 808 if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point)) |
| 812 pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); | |
| 813 if (bRet) { | |
| 814 SetFocusAnnot(pFXAnnot); | 809 SetFocusAnnot(pFXAnnot); |
| 815 } | 810 |
| 816 return TRUE; | 811 return TRUE; |
| 817 } | 812 } |
| 818 #endif // PDF_ENABLE_XFA | 813 #endif // PDF_ENABLE_XFA |
| 819 | 814 |
| 820 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, | 815 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CFX_FloatPoint& point, |
| 821 FX_UINT nFlag) { | 816 FX_UINT nFlag) { |
| 822 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 817 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 823 ASSERT(pEnv); | 818 ASSERT(pEnv); |
| 824 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 819 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 825 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 820 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 } | 891 } |
| 897 return FALSE; | 892 return FALSE; |
| 898 } | 893 } |
| 899 | 894 |
| 900 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { | 895 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
| 901 return FALSE; | 896 return FALSE; |
| 902 } | 897 } |
| 903 | 898 |
| 904 void CPDFSDK_PageView::LoadFXAnnots() { | 899 void CPDFSDK_PageView::LoadFXAnnots() { |
| 905 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 900 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 906 #ifdef PDF_ENABLE_XFA | |
| 907 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 901 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 908 #else | |
| 909 FX_BOOL bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); | |
| 910 // Disable the default AP construction. | |
| 911 CPDF_InterForm::SetUpdateAP(FALSE); | |
| 912 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); | |
| 913 CPDF_InterForm::SetUpdateAP(bUpdateAP); | |
| 914 const size_t nCount = m_pAnnotList->Count(); | |
| 915 #endif // PDF_ENABLE_XFA | |
| 916 | 902 |
| 917 SetLock(TRUE); | 903 SetLock(TRUE); |
| 918 | 904 |
| 919 #ifdef PDF_ENABLE_XFA | 905 #ifdef PDF_ENABLE_XFA |
| 920 CFX_RetainPtr<CPDFXFA_Page> protector(m_page); | 906 CFX_RetainPtr<CPDFXFA_Page> protector(m_page); |
| 921 if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { | 907 if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
| 922 CXFA_FFPageView* pageView = m_page->GetXFAPageView(); | 908 CXFA_FFPageView* pageView = m_page->GetXFAPageView(); |
| 923 std::unique_ptr<IXFA_WidgetIterator> pWidgetHander( | 909 std::unique_ptr<IXFA_WidgetIterator> pWidgetHander( |
| 924 pageView->CreateWidgetIterator( | 910 pageView->CreateWidgetIterator( |
| 925 XFA_TRAVERSEWAY_Form, | 911 XFA_TRAVERSEWAY_Form, |
| 926 XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); | 912 XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)); |
| 927 if (!pWidgetHander) { | 913 if (!pWidgetHander) { |
| 928 SetLock(FALSE); | 914 SetLock(FALSE); |
| 929 return; | 915 return; |
| 930 } | 916 } |
| 931 | 917 |
| 932 while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) { | 918 while (CXFA_FFWidget* pXFAAnnot = pWidgetHander->MoveToNext()) { |
| 933 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); | 919 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
| 934 if (!pAnnot) | 920 if (!pAnnot) |
| 935 continue; | 921 continue; |
| 936 m_fxAnnotArray.push_back(pAnnot); | 922 m_fxAnnotArray.push_back(pAnnot); |
| 937 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | 923 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 938 } | 924 } |
| 939 } else { | |
| 940 CPDF_Page* pPage = m_page->GetPDFPage(); | |
| 941 ASSERT(pPage); | |
| 942 FX_BOOL bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); | |
| 943 // Disable the default AP construction. | |
| 944 CPDF_InterForm::SetUpdateAP(FALSE); | |
| 945 m_pAnnotList.reset(new CPDF_AnnotList(pPage)); | |
| 946 CPDF_InterForm::SetUpdateAP(bUpdateAP); | |
| 947 | 925 |
| 948 const size_t nCount = m_pAnnotList->Count(); | 926 SetLock(FALSE); |
| 949 for (size_t i = 0; i < nCount; ++i) { | 927 return; |
| 950 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); | 928 } |
| 951 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); | 929 #endif // PDF_ENABLE_XFA |
| 952 | 930 |
| 953 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); | 931 CPDF_Page* pPage = GetPDFPage(); |
| 954 if (!pAnnot) | 932 ASSERT(pPage); |
| 955 continue; | 933 FX_BOOL bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); |
| 956 m_fxAnnotArray.push_back(pAnnot); | 934 // Disable the default AP construction. |
| 957 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | 935 CPDF_InterForm::SetUpdateAP(FALSE); |
| 958 } | 936 m_pAnnotList.reset(new CPDF_AnnotList(pPage)); |
| 959 } | 937 CPDF_InterForm::SetUpdateAP(bUpdateAP); |
| 960 #else // PDF_ENABLE_XFA | 938 |
| 939 const size_t nCount = m_pAnnotList->Count(); |
| 961 for (size_t i = 0; i < nCount; ++i) { | 940 for (size_t i = 0; i < nCount; ++i) { |
| 962 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); | 941 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 963 CPDF_Document* pDoc = GetPDFDocument(); | 942 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
| 964 CheckUnSupportAnnot(pDoc, pPDFAnnot); | |
| 965 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | |
| 966 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); | 943 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 967 if (!pAnnot) | 944 if (!pAnnot) |
| 968 continue; | 945 continue; |
| 969 m_fxAnnotArray.push_back(pAnnot); | 946 m_fxAnnotArray.push_back(pAnnot); |
| 970 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | 947 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 971 } | 948 } |
| 972 #endif // PDF_ENABLE_XFA | |
| 973 | 949 |
| 974 SetLock(FALSE); | 950 SetLock(FALSE); |
| 975 } | 951 } |
| 976 | 952 |
| 977 void CPDFSDK_PageView::ClearFXAnnots() { | 953 void CPDFSDK_PageView::ClearFXAnnots() { |
| 978 SetLock(TRUE); | 954 SetLock(TRUE); |
| 979 if (m_pSDKDoc && GetFocusAnnot()) | 955 if (m_pSDKDoc && GetFocusAnnot()) |
| 980 m_pSDKDoc->SetFocusAnnot(nullptr); | 956 m_pSDKDoc->SetFocusAnnot(nullptr); |
| 981 m_CaptureWidget = nullptr; | 957 m_CaptureWidget = nullptr; |
| 982 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) | 958 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 return nullptr; | 1015 return nullptr; |
| 1040 | 1016 |
| 1041 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 1017 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 1042 if (pAnnot == pFocusAnnot) | 1018 if (pAnnot == pFocusAnnot) |
| 1043 return pAnnot; | 1019 return pAnnot; |
| 1044 } | 1020 } |
| 1045 return nullptr; | 1021 return nullptr; |
| 1046 } | 1022 } |
| 1047 | 1023 |
| 1048 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { | 1024 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
| 1049 #ifdef PDF_ENABLE_XFA | 1025 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; |
| 1050 CPDF_Page* pPage = m_page->GetPDFPage(); | |
| 1051 #else // PDF_ENABLE_XFA | |
| 1052 CPDF_Page* pPage = m_page; | |
| 1053 #endif // PDF_ENABLE_XFA | |
| 1054 CPDF_Dictionary* pDict = pPage->m_pFormDict; | |
| 1055 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | 1026 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
| 1056 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; | 1027 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
| 1057 } | 1028 } |
| OLD | NEW |