| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "fpdfsdk/include/fsdk_mgr.h" | 9 #include "fpdfsdk/include/fsdk_mgr.h" |
| 10 | 10 |
| 11 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" | 11 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" |
| 12 #include "fpdfsdk/include/fsdk_define.h" | 12 #include "fpdfsdk/include/fsdk_define.h" |
| 13 #include "fpdfsdk/include/javascript/IJavaScript.h" | 13 #include "fpdfsdk/include/javascript/IJavaScript.h" |
| 14 #include "public/fpdf_ext.h" | 14 #include "public/fpdf_ext.h" |
| 15 #include "third_party/base/nonstd_unique_ptr.h" | 15 #include "third_party/base/nonstd_unique_ptr.h" |
| 16 | 16 |
| 17 #ifdef PDF_ENABLE_XFA |
| 18 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 19 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 20 #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 21 #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 22 |
| 23 #endif |
| 17 #if _FX_OS_ == _FX_ANDROID_ | 24 #if _FX_OS_ == _FX_ANDROID_ |
| 18 #include "time.h" | 25 #include "time.h" |
| 19 #else | 26 #else |
| 20 #include <ctime> | 27 #include <ctime> |
| 21 #endif | 28 #endif |
| 22 | 29 |
| 23 class CFX_SystemHandler : public IFX_SystemHandler { | 30 class CFX_SystemHandler : public IFX_SystemHandler { |
| 24 public: | 31 public: |
| 25 explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) | 32 explicit CFX_SystemHandler(CPDFDoc_Environment* pEnv) |
| 26 : m_pEnv(pEnv), m_nCharSet(-1) {} | 33 : m_pEnv(pEnv), m_nCharSet(-1) {} |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 return m_pEnv->FFI_GetLocalTime(); | 207 return m_pEnv->FFI_GetLocalTime(); |
| 201 } | 208 } |
| 202 | 209 |
| 203 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, | 210 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, |
| 204 FPDF_FORMFILLINFO* pFFinfo) | 211 FPDF_FORMFILLINFO* pFFinfo) |
| 205 : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { | 212 : m_pInfo(pFFinfo), m_pSDKDoc(NULL), m_pUnderlyingDoc(pDoc) { |
| 206 m_pSysHandler.reset(new CFX_SystemHandler(this)); | 213 m_pSysHandler.reset(new CFX_SystemHandler(this)); |
| 207 } | 214 } |
| 208 | 215 |
| 209 CPDFDoc_Environment::~CPDFDoc_Environment() { | 216 CPDFDoc_Environment::~CPDFDoc_Environment() { |
| 217 #ifdef PDF_ENABLE_XFA |
| 218 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 219 if (pProvider->m_pEnvList.GetSize() == 0) |
| 220 pProvider->SetJavaScriptInitialized(FALSE); |
| 221 #endif |
| 210 } | 222 } |
| 211 | 223 |
| 212 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, | 224 int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, |
| 213 const FX_WCHAR* Title, | 225 const FX_WCHAR* Title, |
| 214 FX_UINT Type, | 226 FX_UINT Type, |
| 215 FX_UINT Icon) { | 227 FX_UINT Icon) { |
| 216 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { | 228 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) { |
| 217 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); | 229 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 218 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); | 230 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 219 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); | 231 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return TRUE; | 535 return TRUE; |
| 524 | 536 |
| 525 if (m_pFocusAnnot) { | 537 if (m_pFocusAnnot) { |
| 526 if (!KillFocusAnnot(nFlag)) | 538 if (!KillFocusAnnot(nFlag)) |
| 527 return FALSE; | 539 return FALSE; |
| 528 } | 540 } |
| 529 | 541 |
| 530 if (!pAnnot) | 542 if (!pAnnot) |
| 531 return FALSE; | 543 return FALSE; |
| 532 | 544 |
| 545 #ifdef PDF_ENABLE_XFA |
| 546 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
| 547 #endif |
| 533 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | 548 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
| 534 if (pPageView && pPageView->IsValid()) { | 549 if (pPageView && pPageView->IsValid()) { |
| 535 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); | 550 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
| 536 if (!m_pFocusAnnot) { | 551 if (!m_pFocusAnnot) { |
| 552 #ifdef PDF_ENABLE_XFA |
| 553 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, pLastFocusAnnot)) |
| 554 return FALSE; |
| 555 |
| 556 #endif |
| 537 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) | 557 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, nFlag)) |
| 538 return FALSE; | 558 return FALSE; |
| 539 if (!m_pFocusAnnot) { | 559 if (!m_pFocusAnnot) { |
| 540 m_pFocusAnnot = pAnnot; | 560 m_pFocusAnnot = pAnnot; |
| 541 return TRUE; | 561 return TRUE; |
| 542 } | 562 } |
| 543 } | 563 } |
| 544 } | 564 } |
| 545 return FALSE; | 565 return FALSE; |
| 546 } | 566 } |
| 547 | 567 |
| 548 FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { | 568 FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { |
| 549 if (m_pFocusAnnot) { | 569 if (m_pFocusAnnot) { |
| 550 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); | 570 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pEnv->GetAnnotHandlerMgr(); |
| 551 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; | 571 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
| 552 m_pFocusAnnot = nullptr; | 572 m_pFocusAnnot = nullptr; |
| 573 #ifdef PDF_ENABLE_XFA |
| 574 |
| 575 if (!pAnnotHandler->Annot_OnChangeFocus(nullptr, pFocusAnnot)) |
| 576 return FALSE; |
| 577 |
| 578 #endif |
| 553 if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { | 579 if (pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) { |
| 554 if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) { | 580 if (pFocusAnnot->GetType() == FX_BSTRC("Widget")) { |
| 555 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; | 581 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
| 556 int nFieldType = pWidget->GetFieldType(); | 582 int nFieldType = pWidget->GetFieldType(); |
| 557 if (FIELDTYPE_TEXTFIELD == nFieldType || | 583 if (FIELDTYPE_TEXTFIELD == nFieldType || |
| 558 FIELDTYPE_COMBOBOX == nFieldType) { | 584 FIELDTYPE_COMBOBOX == nFieldType) { |
| 559 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); | 585 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); |
| 560 } | 586 } |
| 561 } | 587 } |
| 562 | 588 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 589 | 615 |
| 590 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, | 616 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
| 591 UnderlyingPageType* page) | 617 UnderlyingPageType* page) |
| 592 : m_page(page), | 618 : m_page(page), |
| 593 m_pSDKDoc(pSDKDoc), | 619 m_pSDKDoc(pSDKDoc), |
| 594 m_CaptureWidget(nullptr), | 620 m_CaptureWidget(nullptr), |
| 595 m_bEnterWidget(FALSE), | 621 m_bEnterWidget(FALSE), |
| 596 m_bExitWidget(FALSE), | 622 m_bExitWidget(FALSE), |
| 597 m_bOnWidget(FALSE), | 623 m_bOnWidget(FALSE), |
| 598 m_bValid(FALSE), | 624 m_bValid(FALSE), |
| 625 #ifndef PDF_ENABLE_XFA |
| 599 m_bLocked(FALSE), | 626 m_bLocked(FALSE), |
| 600 m_bTakeOverPage(FALSE) { | 627 m_bTakeOverPage(FALSE) { |
| 628 #else |
| 629 m_bLocked(FALSE) { |
| 630 #endif |
| 601 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); | 631 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
| 602 if (pInterForm) { | 632 if (pInterForm) { |
| 603 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 633 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 634 #ifndef PDF_ENABLE_XFA |
| 604 pPDFInterForm->FixPageFields(page); | 635 pPDFInterForm->FixPageFields(page); |
| 636 #else |
| 637 if (page->GetPDFPage()) |
| 638 pPDFInterForm->FixPageFields(page->GetPDFPage()); |
| 639 #endif |
| 605 } | 640 } |
| 641 #ifndef PDF_ENABLE_XFA |
| 606 m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); | 642 m_page->SetPrivateData((void*)m_page, (void*)this, nullptr); |
| 643 #endif |
| 607 } | 644 } |
| 608 | 645 |
| 609 CPDFSDK_PageView::~CPDFSDK_PageView() { | 646 CPDFSDK_PageView::~CPDFSDK_PageView() { |
| 610 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 647 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 611 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 648 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 612 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) | 649 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
| 613 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); | 650 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
| 614 m_fxAnnotArray.clear(); | 651 m_fxAnnotArray.clear(); |
| 615 | 652 |
| 616 m_pAnnotList.reset(); | 653 m_pAnnotList.reset(); |
| 654 #ifndef PDF_ENABLE_XFA |
| 617 | 655 |
| 618 m_page->RemovePrivateData((void*)m_page); | 656 m_page->RemovePrivateData((void*)m_page); |
| 619 if (m_bTakeOverPage) { | 657 if (m_bTakeOverPage) { |
| 620 delete m_page; | 658 delete m_page; |
| 621 } | 659 } |
| 660 #endif |
| 622 } | 661 } |
| 623 | 662 |
| 624 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, | 663 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 625 CPDF_Matrix* pUser2Device, | 664 CPDF_Matrix* pUser2Device, |
| 665 #ifndef PDF_ENABLE_XFA |
| 626 CPDF_RenderOptions* pOptions) { | 666 CPDF_RenderOptions* pOptions) { |
| 667 #else |
| 668 CPDF_RenderOptions* pOptions, |
| 669 const FX_RECT& pClip) { |
| 670 #endif |
| 627 m_curMatrix = *pUser2Device; | 671 m_curMatrix = *pUser2Device; |
| 628 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 672 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 673 #ifdef PDF_ENABLE_XFA |
| 674 CPDFXFA_Page* pPage = GetPDFXFAPage(); |
| 675 if (pPage == NULL) |
| 676 return; |
| 677 |
| 678 #ifdef PDF_ENABLE_XFA |
| 679 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
| 680 CFX_Graphics gs; |
| 681 gs.Create(pDevice); |
| 682 CFX_RectF rectClip; |
| 683 rectClip.Set(static_cast<FX_FLOAT>(pClip.left), |
| 684 static_cast<FX_FLOAT>(pClip.top), |
| 685 static_cast<FX_FLOAT>(pClip.Width()), |
| 686 static_cast<FX_FLOAT>(pClip.Height())); |
| 687 gs.SetClipRect(rectClip); |
| 688 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); |
| 689 if (!pRenderContext) |
| 690 return; |
| 691 CXFA_RenderOptions renderOptions; |
| 692 renderOptions.m_bHighlight = TRUE; |
| 693 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, |
| 694 renderOptions); |
| 695 pRenderContext->DoRender(); |
| 696 pRenderContext->StopRender(); |
| 697 pRenderContext->Release(); |
| 698 return; |
| 699 } |
| 700 #endif // PDF_ENABLE_XFA |
| 701 |
| 702 // for pdf/static xfa. |
| 703 #endif |
| 629 CPDFSDK_AnnotIterator annotIterator(this, true); | 704 CPDFSDK_AnnotIterator annotIterator(this, true); |
| 630 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { | 705 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
| 631 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 706 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 632 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); | 707 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
| 633 } | 708 } |
| 634 } | 709 } |
| 635 | 710 |
| 636 const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, | 711 const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, |
| 637 FX_FLOAT pageY) { | 712 FX_FLOAT pageY) { |
| 638 for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { | 713 for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 745 |
| 671 return nullptr; | 746 return nullptr; |
| 672 } | 747 } |
| 673 | 748 |
| 674 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, | 749 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, |
| 675 FX_FLOAT pageY) { | 750 FX_FLOAT pageY) { |
| 676 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 751 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 677 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); | 752 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
| 678 CPDFSDK_AnnotIterator annotIterator(this, false); | 753 CPDFSDK_AnnotIterator annotIterator(this, false); |
| 679 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { | 754 while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { |
| 755 #ifndef PDF_ENABLE_XFA |
| 680 if (pSDKAnnot->GetType() == "Widget") { | 756 if (pSDKAnnot->GetType() == "Widget") { |
| 757 #else |
| 758 bool bHitTest = pSDKAnnot->GetType() == "Widget"; |
| 759 bHitTest = bHitTest || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME; |
| 760 if (bHitTest) { |
| 761 #endif |
| 681 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); | 762 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 682 CPDF_Point point(pageX, pageY); | 763 CPDF_Point point(pageX, pageY); |
| 683 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) | 764 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
| 684 return pSDKAnnot; | 765 return pSDKAnnot; |
| 685 } | 766 } |
| 686 } | 767 } |
| 687 | 768 |
| 688 return nullptr; | 769 return nullptr; |
| 689 } | 770 } |
| 690 | 771 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 711 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); | 792 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
| 712 CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); | 793 CPDFSDK_Annot* pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 713 if (!pSDKAnnot) | 794 if (!pSDKAnnot) |
| 714 return nullptr; | 795 return nullptr; |
| 715 | 796 |
| 716 m_fxAnnotArray.push_back(pSDKAnnot); | 797 m_fxAnnotArray.push_back(pSDKAnnot); |
| 717 pAnnotHandler->Annot_OnCreate(pSDKAnnot); | 798 pAnnotHandler->Annot_OnCreate(pSDKAnnot); |
| 718 return pSDKAnnot; | 799 return pSDKAnnot; |
| 719 } | 800 } |
| 720 | 801 |
| 802 #ifdef PDF_ENABLE_XFA |
| 803 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { |
| 804 if (!pPDFAnnot) |
| 805 return nullptr; |
| 806 |
| 807 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 808 if (pSDKAnnot) |
| 809 return pSDKAnnot; |
| 810 |
| 811 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 812 CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr(); |
| 813 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 814 if (!pSDKAnnot) |
| 815 return nullptr; |
| 816 |
| 817 m_fxAnnotArray.push_back(pSDKAnnot); |
| 818 return pSDKAnnot; |
| 819 } |
| 820 |
| 821 #endif |
| 721 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { | 822 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary* pDict) { |
| 722 return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; | 823 return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; |
| 723 } | 824 } |
| 724 | 825 |
| 725 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, | 826 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType, |
| 726 CPDF_Dictionary* pDict) { | 827 CPDF_Dictionary* pDict) { |
| 727 return NULL; | 828 return NULL; |
| 728 } | 829 } |
| 729 | 830 |
| 730 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { | 831 FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { |
| 832 #ifndef PDF_ENABLE_XFA |
| 731 return FALSE; | 833 return FALSE; |
| 834 #else |
| 835 if (!pAnnot) |
| 836 return FALSE; |
| 837 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 838 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && |
| 839 pPage->GetDocument()->GetDocType() != DOCTYPE_DYNAMIC_XFA)) |
| 840 return FALSE; |
| 841 |
| 842 auto it = std::find(m_fxAnnotArray.begin(), m_fxAnnotArray.end(), pAnnot); |
| 843 if (it != m_fxAnnotArray.end()) |
| 844 m_fxAnnotArray.erase(it); |
| 845 if (m_CaptureWidget == pAnnot) |
| 846 m_CaptureWidget = nullptr; |
| 847 |
| 848 return TRUE; |
| 849 #endif |
| 732 } | 850 } |
| 733 | 851 |
| 734 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { | 852 CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { |
| 735 if (m_page) { | 853 if (m_page) { |
| 854 #ifndef PDF_ENABLE_XFA |
| 736 return m_page->m_pDocument; | 855 return m_page->m_pDocument; |
| 856 #else |
| 857 return m_page->GetDocument()->GetPDFDoc(); |
| 737 } | 858 } |
| 738 return NULL; | 859 return NULL; |
| 739 } | 860 } |
| 861 |
| 862 CPDF_Page* CPDFSDK_PageView::GetPDFPage() { |
| 863 if (m_page) { |
| 864 return m_page->GetPDFPage(); |
| 865 #endif |
| 866 } |
| 867 return NULL; |
| 868 } |
| 740 | 869 |
| 741 size_t CPDFSDK_PageView::CountAnnots() const { | 870 size_t CPDFSDK_PageView::CountAnnots() const { |
| 742 return m_fxAnnotArray.size(); | 871 return m_fxAnnotArray.size(); |
| 743 } | 872 } |
| 744 | 873 |
| 745 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { | 874 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(size_t nIndex) { |
| 746 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; | 875 return nIndex < m_fxAnnotArray.size() ? m_fxAnnotArray[nIndex] : nullptr; |
| 747 } | 876 } |
| 748 | 877 |
| 749 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { | 878 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary* pDict) { |
| 750 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 879 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 751 if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) | 880 if (pAnnot->GetPDFAnnot()->GetAnnotDict() == pDict) |
| 752 return pAnnot; | 881 return pAnnot; |
| 753 } | 882 } |
| 754 return nullptr; | 883 return nullptr; |
| 755 } | 884 } |
| 885 #ifdef PDF_ENABLE_XFA |
| 886 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { |
| 887 if (!hWidget) |
| 888 return nullptr; |
| 889 |
| 890 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 891 if (pAnnot->GetXFAWidget() == hWidget) |
| 892 return pAnnot; |
| 893 } |
| 894 return nullptr; |
| 895 } |
| 896 #endif |
| 756 | 897 |
| 757 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, | 898 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point& point, |
| 758 FX_UINT nFlag) { | 899 FX_UINT nFlag) { |
| 759 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 900 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 760 ASSERT(pEnv); | 901 ASSERT(pEnv); |
| 761 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 902 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 762 if (!pFXAnnot) { | 903 if (!pFXAnnot) { |
| 763 KillFocusAnnot(nFlag); | 904 KillFocusAnnot(nFlag); |
| 764 return FALSE; | 905 return FALSE; |
| 765 } | 906 } |
| 766 | 907 |
| 767 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 908 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 768 FX_BOOL bRet = | 909 FX_BOOL bRet = |
| 769 pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); | 910 pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag, point); |
| 770 if (bRet) | 911 if (bRet) |
| 771 SetFocusAnnot(pFXAnnot); | 912 SetFocusAnnot(pFXAnnot); |
| 772 return bRet; | 913 return bRet; |
| 773 } | 914 } |
| 774 | 915 |
| 916 #ifdef PDF_ENABLE_XFA |
| 917 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point& point, |
| 918 FX_UINT nFlag) { |
| 919 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 920 ASSERT(pEnv); |
| 921 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 922 ASSERT(pAnnotHandlerMgr); |
| 923 |
| 924 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 925 |
| 926 if (pFXAnnot == NULL) |
| 927 return FALSE; |
| 928 |
| 929 FX_BOOL bRet = |
| 930 pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag, point); |
| 931 if (bRet) { |
| 932 SetFocusAnnot(pFXAnnot); |
| 933 } |
| 934 return TRUE; |
| 935 } |
| 936 |
| 937 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 938 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 939 ASSERT(pEnv); |
| 940 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 941 |
| 942 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 943 |
| 944 if (pFXAnnot == NULL) |
| 945 return FALSE; |
| 946 |
| 947 FX_BOOL bRet = |
| 948 pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag, point); |
| 949 if (bRet) { |
| 950 SetFocusAnnot(pFXAnnot); |
| 951 } |
| 952 return TRUE; |
| 953 } |
| 954 |
| 955 #endif |
| 775 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { | 956 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag) { |
| 776 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 957 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 777 ASSERT(pEnv); | 958 ASSERT(pEnv); |
| 778 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 959 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 779 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); | 960 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 780 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); | 961 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); |
| 781 FX_BOOL bRet = FALSE; | 962 FX_BOOL bRet = FALSE; |
| 782 if (pFocusAnnot && pFocusAnnot != pFXAnnot) { | 963 if (pFocusAnnot && pFocusAnnot != pFXAnnot) { |
| 783 // Last focus Annot gets a chance to handle the event. | 964 // Last focus Annot gets a chance to handle the event. |
| 784 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); | 965 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag, point); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 } | 1031 } |
| 851 return FALSE; | 1032 return FALSE; |
| 852 } | 1033 } |
| 853 | 1034 |
| 854 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { | 1035 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { |
| 855 return FALSE; | 1036 return FALSE; |
| 856 } | 1037 } |
| 857 | 1038 |
| 858 void CPDFSDK_PageView::LoadFXAnnots() { | 1039 void CPDFSDK_PageView::LoadFXAnnots() { |
| 859 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 1040 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1041 #ifdef PDF_ENABLE_XFA |
| 1042 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1043 #endif |
| 860 | 1044 |
| 1045 #ifndef PDF_ENABLE_XFA |
| 861 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); | 1046 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 862 // Disable the default AP construction. | 1047 // Disable the default AP construction. |
| 863 CPDF_InterForm::EnableUpdateAP(FALSE); | 1048 CPDF_InterForm::EnableUpdateAP(FALSE); |
| 864 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); | 1049 m_pAnnotList.reset(new CPDF_AnnotList(m_page)); |
| 865 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); | 1050 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
| 866 const size_t nCount = m_pAnnotList->Count(); | 1051 const size_t nCount = m_pAnnotList->Count(); |
| 1052 #endif |
| 867 SetLock(TRUE); | 1053 SetLock(TRUE); |
| 1054 #ifndef PDF_ENABLE_XFA |
| 868 for (size_t i = 0; i < nCount; ++i) { | 1055 for (size_t i = 0; i < nCount; ++i) { |
| 869 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); | 1056 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 870 CPDF_Document* pDoc = GetPDFDocument(); | 1057 CPDF_Document* pDoc = GetPDFDocument(); |
| 1058 #else |
| 1059 m_page->AddRef(); |
| 1060 if (m_pSDKDoc->GetXFADocument()->GetDocType() == DOCTYPE_DYNAMIC_XFA) { |
| 1061 IXFA_PageView* pageView = NULL; |
| 1062 pageView = m_page->GetXFAPageView(); |
| 1063 ASSERT(pageView != NULL); |
| 871 | 1064 |
| 1065 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator( |
| 1066 XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible | |
| 1067 XFA_WIDGETFILTER_Viewable | |
| 1068 XFA_WIDGETFILTER_AllType); |
| 1069 if (!pWidgetHander) { |
| 1070 m_page->Release(); |
| 1071 SetLock(FALSE); |
| 1072 return; |
| 1073 } |
| 1074 |
| 1075 while (IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext()) { |
| 1076 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
| 1077 if (!pAnnot) |
| 1078 continue; |
| 1079 |
| 1080 m_fxAnnotArray.push_back(pAnnot); |
| 1081 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1082 } |
| 1083 #endif |
| 1084 |
| 1085 #ifndef PDF_ENABLE_XFA |
| 872 CheckUnSupportAnnot(pDoc, pPDFAnnot); | 1086 CheckUnSupportAnnot(pDoc, pPDFAnnot); |
| 1087 #else |
| 1088 pWidgetHander->Release(); |
| 1089 } else { |
| 1090 CPDF_Page* pPage = m_page->GetPDFPage(); |
| 1091 ASSERT(pPage != NULL); |
| 1092 #endif |
| 873 | 1093 |
| 1094 #ifndef PDF_ENABLE_XFA |
| 874 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 1095 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 875 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); | 1096 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 876 if (!pAnnot) | 1097 if (!pAnnot) |
| 877 continue; | 1098 continue; |
| 878 m_fxAnnotArray.push_back(pAnnot); | 1099 m_fxAnnotArray.push_back(pAnnot); |
| 1100 #else |
| 1101 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 1102 // Disable the default AP construction. |
| 1103 CPDF_InterForm::EnableUpdateAP(FALSE); |
| 1104 m_pAnnotList.reset(new CPDF_AnnotList(pPage)); |
| 1105 CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
| 879 | 1106 |
| 1107 const size_t nCount = m_pAnnotList->Count(); |
| 1108 for (size_t i = 0; i < nCount; ++i) { |
| 1109 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 1110 CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot); |
| 1111 |
| 1112 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 1113 if (!pAnnot) |
| 1114 continue; |
| 1115 m_fxAnnotArray.push_back(pAnnot); |
| 1116 #endif |
| 1117 |
| 1118 #ifndef PDF_ENABLE_XFA |
| 880 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); | 1119 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1120 #else |
| 1121 pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1122 } |
| 1123 #endif |
| 881 } | 1124 } |
| 1125 #ifdef PDF_ENABLE_XFA |
| 1126 m_page->Release(); |
| 1127 #endif |
| 882 SetLock(FALSE); | 1128 SetLock(FALSE); |
| 883 } | 1129 } |
| 884 | 1130 |
| 885 void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { | 1131 void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { |
| 886 for (int i = 0; i < rects.GetSize(); i++) { | 1132 for (int i = 0; i < rects.GetSize(); i++) { |
| 887 CPDF_Rect rc = rects.GetAt(i); | 1133 CPDF_Rect rc = rects.GetAt(i); |
| 888 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 1134 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 889 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); | 1135 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
| 890 } | 1136 } |
| 891 } | 1137 } |
| 892 | 1138 |
| 893 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { | 1139 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
| 894 CPDF_Rect rcWindow = pAnnot->GetRect(); | 1140 CPDF_Rect rcWindow = pAnnot->GetRect(); |
| 895 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 1141 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 896 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, | 1142 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, |
| 897 rcWindow.bottom); | 1143 rcWindow.bottom); |
| 898 } | 1144 } |
| 899 | 1145 |
| 900 int CPDFSDK_PageView::GetPageIndex() { | 1146 int CPDFSDK_PageView::GetPageIndex() { |
| 901 if (m_page) { | 1147 if (m_page) { |
| 1148 #ifndef PDF_ENABLE_XFA |
| 902 CPDF_Dictionary* pDic = m_page->m_pFormDict; | 1149 CPDF_Dictionary* pDic = m_page->m_pFormDict; |
| 1150 #else |
| 1151 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
| 1152 #endif |
| 903 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | 1153 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
| 904 if (pDoc && pDic) { | 1154 if (pDoc && pDic) { |
| 905 return pDoc->GetPageIndex(pDic->GetObjNum()); | 1155 return pDoc->GetPageIndex(pDic->GetObjNum()); |
| 906 } | 1156 } |
| 907 } | 1157 } |
| 908 return -1; | 1158 return -1; |
| 909 } | 1159 } |
| 910 | 1160 |
| 911 bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { | 1161 bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
| 912 if (!p) | 1162 if (!p) |
| 913 return false; | 1163 return false; |
| 914 | 1164 |
| 915 const auto& annots = m_pAnnotList->All(); | 1165 const auto& annots = m_pAnnotList->All(); |
| 916 return std::find(annots.begin(), annots.end(), p) != annots.end(); | 1166 return std::find(annots.begin(), annots.end(), p) != annots.end(); |
| 917 } | 1167 } |
| 918 | 1168 |
| 919 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { | 1169 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
| 920 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 1170 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
| 921 if (!pFocusAnnot) | 1171 if (!pFocusAnnot) |
| 922 return nullptr; | 1172 return nullptr; |
| 923 | 1173 |
| 924 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 1174 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
| 925 if (pAnnot == pFocusAnnot) | 1175 if (pAnnot == pFocusAnnot) |
| 926 return pAnnot; | 1176 return pAnnot; |
| 927 } | 1177 } |
| 928 return nullptr; | 1178 return nullptr; |
| 929 } | 1179 } |
| OLD | NEW |