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 "public/fpdf_formfill.h" | 7 #include "public/fpdf_formfill.h" |
8 | 8 |
9 #include "../include/fpdfxfa/fpdfxfa_app.h" | 9 #include "../include/fpdfxfa/fpdfxfa_app.h" |
10 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 10 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 return pEnv ? pEnv->GetSDKDocument() : nullptr; | 21 return pEnv ? pEnv->GetSDKDocument() : nullptr; |
22 } | 22 } |
23 | 23 |
24 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | 24 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
25 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); | 25 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
26 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; | 26 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; |
27 } | 27 } |
28 | 28 |
29 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 29 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
30 FPDF_PAGE page) { | 30 FPDF_PAGE page) { |
31 if (!page) | 31 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
32 if (!pPage) | |
32 return nullptr; | 33 return nullptr; |
33 | 34 |
34 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); | 35 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
35 return pSDKDoc ? pSDKDoc->GetPageView((CPDFXFA_Page*)page, TRUE) : nullptr; | 36 return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr; |
36 } | 37 } |
37 | 38 |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, | 41 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
41 FPDF_PAGE page, | 42 FPDF_PAGE page, |
42 double page_x, | 43 double page_x, |
43 double page_y) { | 44 double page_y) { |
44 if (!hHandle) | 45 if (!hHandle) |
45 return -1; | 46 return -1; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 CPDF_InterForm interform(pPage->m_pDocument, FALSE); | 122 CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
122 int z_order = -1; | 123 int z_order = -1; |
123 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, | 124 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, |
124 &z_order); | 125 &z_order); |
125 return z_order; | 126 return z_order; |
126 } | 127 } |
127 | 128 |
128 DLLEXPORT FPDF_FORMHANDLE STDCALL | 129 DLLEXPORT FPDF_FORMHANDLE STDCALL |
129 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, | 130 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
130 FPDF_FORMFILLINFO* formInfo) { | 131 FPDF_FORMFILLINFO* formInfo) { |
131 if (!document || !formInfo || formInfo->version != 2) | 132 const int kRequiredVersion = 2; |
Tom Sepez
2015/11/24 21:00:34
e.g. will avoid an ifdef in the middle of a no-{}
Lei Zhang
2015/11/24 21:22:44
Acknowledged.
| |
133 if (!formInfo || formInfo->version != kRequiredVersion) | |
132 return nullptr; | 134 return nullptr; |
133 | 135 |
134 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; | 136 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
137 if (!pDocument) | |
138 return nullptr; | |
139 | |
135 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); | 140 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); |
136 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); | 141 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); |
137 | 142 |
138 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); | 143 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
139 pApp->AddFormFillEnv(pEnv); | 144 pApp->AddFormFillEnv(pEnv); |
140 | |
141 return pEnv; | 145 return pEnv; |
142 } | 146 } |
143 | 147 |
144 DLLEXPORT void STDCALL | 148 DLLEXPORT void STDCALL |
145 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 149 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
146 if (!hHandle) | 150 if (!hHandle) |
147 return; | 151 return; |
148 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); | 152 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
149 pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); | 153 pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); |
150 delete (CPDFDoc_Environment*)hHandle; | 154 delete (CPDFDoc_Environment*)hHandle; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 } | 597 } |
594 | 598 |
595 DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, | 599 DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, |
596 FPDF_FORMHANDLE hHandle) { | 600 FPDF_FORMHANDLE hHandle) { |
597 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) | 601 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
598 pPageView->SetValid(TRUE); | 602 pPageView->SetValid(TRUE); |
599 } | 603 } |
600 | 604 |
601 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, | 605 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, |
602 FPDF_FORMHANDLE hHandle) { | 606 FPDF_FORMHANDLE hHandle) { |
603 if (!hHandle || !page) | 607 if (!hHandle) |
604 return; | 608 return; |
605 | 609 |
606 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); | 610 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); |
607 if (!pSDKDoc) | 611 if (!pSDKDoc) |
608 return; | 612 return; |
609 | 613 |
610 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 614 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
615 if (!pPage) | |
616 return; | |
617 | |
611 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); | 618 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); |
612 if (pPageView) { | 619 if (pPageView) { |
613 pPageView->SetValid(FALSE); | 620 pPageView->SetValid(FALSE); |
614 // RemovePageView() takes care of the delete for us. | 621 // RemovePageView() takes care of the delete for us. |
615 pSDKDoc->RemovePageView(pPage); | 622 pSDKDoc->RemovePageView(pPage); |
616 } | 623 } |
617 } | 624 } |
618 | 625 |
619 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { | 626 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
620 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); | 627 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
(...skipping 25 matching lines...) Expand all Loading... | |
646 ((CPDFDoc_Environment*)hHandle)->GetActionHander(); | 653 ((CPDFDoc_Environment*)hHandle)->GetActionHander(); |
647 ASSERT(pActionHandler != NULL); | 654 ASSERT(pActionHandler != NULL); |
648 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, | 655 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
649 pSDKDoc); | 656 pSDKDoc); |
650 } | 657 } |
651 } | 658 } |
652 | 659 |
653 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, | 660 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, |
654 FPDF_FORMHANDLE hHandle, | 661 FPDF_FORMHANDLE hHandle, |
655 int aaType) { | 662 int aaType) { |
656 if (!hHandle || !page) | 663 if (!hHandle) |
657 return; | 664 return; |
658 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); | 665 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); |
659 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 666 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
660 CPDF_Page* pPDFPage = pPage->GetPDFPage(); | 667 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
661 if (!pPDFPage) | 668 if (!pPDFPage) |
662 return; | 669 return; |
663 if (pSDKDoc->GetPageView(pPage, FALSE)) { | 670 if (pSDKDoc->GetPageView(pPage, FALSE)) { |
664 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); | 671 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); |
665 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 672 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
666 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; | 673 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
667 CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA")); | 674 CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA")); |
668 if (FPDFPAGE_AACTION_OPEN == aaType) { | 675 if (FPDFPAGE_AACTION_OPEN == aaType) { |
669 if (aa.ActionExist(CPDF_AAction::OpenPage)) { | 676 if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
670 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 677 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
671 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 678 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
672 } | 679 } |
673 } else { | 680 } else { |
674 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 681 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
675 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 682 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
676 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 683 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
677 } | 684 } |
678 } | 685 } |
679 } | 686 } |
680 } | 687 } |
OLD | NEW |