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 | a6d9f0e | 2015-06-13 00:48:38 -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 | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_formfill.h" |
| 8 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 9 | #include <memory> |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 10 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 11 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 69d9c68 | 2016-10-04 12:18:35 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/render/cpdf_renderoptions.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 16 | #include "core/fpdfdoc/cpdf_formfield.h" |
| 17 | #include "core/fpdfdoc/cpdf_interform.h" |
| 18 | #include "core/fpdfdoc/cpdf_occontext.h" |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 19 | #include "core/fxge/cfx_defaultrenderdevice.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 20 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 22 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 23 | #include "fpdfsdk/fsdk_actionhandler.h" |
| 24 | #include "fpdfsdk/fsdk_define.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 25 | #include "public/fpdfview.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 26 | #include "third_party/base/ptr_util.h" |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 27 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 29 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 30 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 31 | #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 32 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 33 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 34 | #include "xfa/fxfa/cxfa_ffwidget.h" |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 35 | |
| 36 | static_assert(static_cast<int>(XFA_DocType::PDF) == DOCTYPE_PDF, |
| 37 | "PDF doctype must match"); |
| 38 | static_assert(static_cast<int>(XFA_DocType::Dynamic) == DOCTYPE_DYNAMIC_XFA, |
| 39 | "Dynamic XFA doctype must match"); |
| 40 | static_assert(static_cast<int>(XFA_DocType::Static) == DOCTYPE_STATIC_XFA, |
| 41 | "Static XFA doctype must match"); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 42 | #endif // PDF_ENABLE_XFA |
| 43 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 44 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 45 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 46 | CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment( |
| 47 | FPDF_FORMHANDLE handle) { |
| 48 | return static_cast<CPDFSDK_FormFillEnvironment*>(handle); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 52 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 53 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 54 | return pFormFillEnv ? pFormFillEnv->GetInterForm() : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 55 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 58 | FPDF_PAGE page) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 59 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 60 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | return nullptr; |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 62 | |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 63 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 64 | HandleToCPDFSDKEnvironment(hHandle); |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 65 | return pFormFillEnv ? pFormFillEnv->GetPageView(pPage, true) : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 66 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 67 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 68 | #ifdef PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 69 | std::vector<ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { |
| 70 | return static_cast<std::vector<ByteString>*>(handle); |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 73 | FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<ByteString>* strings) { |
Nicolas Pena | 46abb66 | 2017-05-17 17:23:22 -0400 | [diff] [blame] | 74 | return static_cast<FPDF_STRINGHANDLE>(strings); |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 75 | } |
| 76 | #endif // PDF_ENABLE_XFA |
| 77 | |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 78 | void FFLCommon(FPDF_FORMHANDLE hHandle, |
| 79 | FPDF_BITMAP bitmap, |
| 80 | FPDF_RECORDER recorder, |
| 81 | FPDF_PAGE page, |
| 82 | int start_x, |
| 83 | int start_y, |
| 84 | int size_x, |
| 85 | int size_y, |
| 86 | int rotate, |
| 87 | int flags) { |
| 88 | if (!hHandle) |
| 89 | return; |
| 90 | |
| 91 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 92 | if (!pPage) |
| 93 | return; |
| 94 | |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 95 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 96 | CPDFXFA_Context* pContext = pPage->GetContext(); |
| 97 | if (!pContext) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 98 | return; |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 99 | CPDF_Document* pPDFDoc = pContext->GetPDFDoc(); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 100 | if (!pPDFDoc) |
| 101 | return; |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 102 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 103 | HandleToCPDFSDKEnvironment(hHandle); |
| 104 | if (!pFormFillEnv) |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 105 | return; |
| 106 | #endif // PDF_ENABLE_XFA |
| 107 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 108 | CFX_Matrix matrix = |
| 109 | pPage->GetDisplayMatrix(start_x, start_y, size_x, size_y, rotate); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 110 | FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); |
| 111 | |
Dan Sinclair | a5085d4 | 2017-05-11 16:26:50 -0400 | [diff] [blame] | 112 | auto pDevice = pdfium::MakeUnique<CFX_DefaultRenderDevice>(); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 113 | #ifdef _SKIA_SUPPORT_ |
| 114 | pDevice->AttachRecorder(static_cast<SkPictureRecorder*>(recorder)); |
| 115 | #endif |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame^] | 116 | RetainPtr<CFX_DIBitmap> holder(CFXBitmapFromFPDFBitmap(bitmap)); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 117 | pDevice->Attach(holder, false, nullptr, false); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 118 | { |
| 119 | CFX_RenderDevice::StateRestorer restorer(pDevice.get()); |
| 120 | pDevice->SetClip_Rect(clip); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 121 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 122 | CPDF_RenderOptions options; |
| 123 | if (flags & FPDF_LCD_TEXT) |
| 124 | options.m_Flags |= RENDER_CLEARTYPE; |
| 125 | else |
| 126 | options.m_Flags &= ~RENDER_CLEARTYPE; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 127 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 128 | // Grayscale output |
Dan Sinclair | f55e72e | 2017-07-13 14:53:28 -0400 | [diff] [blame] | 129 | if (flags & FPDF_GRAYSCALE) |
| 130 | options.m_ColorMode = CPDF_RenderOptions::kGray; |
| 131 | |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 132 | options.m_bDrawAnnots = flags & FPDF_ANNOT; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 133 | |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 134 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 135 | options.m_pOCContext = |
| 136 | pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View); |
| 137 | if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true)) |
| 138 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
jaepark | 738766e | 2016-09-02 18:51:44 -0700 | [diff] [blame] | 139 | #else // PDF_ENABLE_XFA |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 140 | options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>( |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 141 | pPage->m_pDocument.Get(), CPDF_OCContext::View); |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 142 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
| 143 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 144 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 1629f60 | 2017-04-21 14:11:26 -0700 | [diff] [blame] | 145 | } |
caryclark | 8f87550 | 2016-12-06 13:49:34 -0800 | [diff] [blame] | 146 | #ifdef _SKIA_SUPPORT_PATHS_ |
Cary Clark | 364d18b | 2017-07-25 10:39:10 -0400 | [diff] [blame] | 147 | pDevice->Flush(true); |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 148 | holder->UnPreMultiply(); |
caryclark | 687fbde | 2016-11-22 12:44:25 -0800 | [diff] [blame] | 149 | #endif |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 152 | } // namespace |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 153 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 154 | FPDF_EXPORT int FPDF_CALLCONV |
| 155 | FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 156 | FPDF_PAGE page, |
| 157 | double page_x, |
| 158 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 159 | if (!hHandle) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 160 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 161 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | if (pPage) { |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 163 | CPDF_InterForm interform(pPage->m_pDocument.Get()); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 164 | CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 165 | pPage, |
| 166 | CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 167 | nullptr); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 168 | if (!pFormCtrl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 171 | return pFormField ? pFormField->GetFieldType() : -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 174 | #ifdef PDF_ENABLE_XFA |
| 175 | CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page); |
| 176 | if (!pXFAPage) |
| 177 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 179 | CXFA_FFPageView* pPageView = pXFAPage->GetXFAPageView(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 180 | if (!pPageView) |
| 181 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 182 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 183 | CXFA_FFDocView* pDocView = pPageView->GetDocView(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 184 | if (!pDocView) |
| 185 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 186 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 187 | CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 188 | if (!pWidgetHandler) |
| 189 | return -1; |
| 190 | |
tsepez | cc4d6d8 | 2016-05-16 13:21:03 -0700 | [diff] [blame] | 191 | std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 192 | pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, |
| 193 | XFA_WidgetStatus_Viewable)); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 194 | if (!pWidgetIterator) |
| 195 | return -1; |
| 196 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 197 | CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext(); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 198 | while (pXFAAnnot) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 199 | CFX_RectF rcBBox = pXFAAnnot->GetBBox(0); |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 200 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 201 | rcBBox.top + rcBBox.height); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 202 | rcWidget.Inflate(1.0f, 1.0f); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 203 | if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x), |
| 204 | static_cast<float>(page_y)))) { |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 205 | return FPDF_FORMFIELD_XFA; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | } |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 207 | pXFAAnnot = pWidgetIterator->MoveToNext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 209 | #endif // PDF_ENABLE_XFA |
Lei Zhang | 7f9fdde | 2016-02-22 20:47:13 -0800 | [diff] [blame] | 210 | return -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 213 | FPDF_EXPORT int FPDF_CALLCONV |
| 214 | FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| 215 | FPDF_PAGE page, |
| 216 | double page_x, |
| 217 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 218 | if (!hHandle) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 219 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 220 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 221 | if (!pPage) |
| 222 | return -1; |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 223 | CPDF_InterForm interform(pPage->m_pDocument.Get()); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 224 | int z_order = -1; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 225 | (void)interform.GetControlAtPoint( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 226 | pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)), |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 227 | &z_order); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 228 | return z_order; |
| 229 | } |
| 230 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 231 | FPDF_EXPORT FPDF_FORMHANDLE FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| 233 | FPDF_FORMFILLINFO* formInfo) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 234 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 235 | const int kRequiredVersion = 2; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 236 | #else // PDF_ENABLE_XFA |
| 237 | const int kRequiredVersion = 1; |
| 238 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 239 | if (!formInfo || formInfo->version != kRequiredVersion) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 240 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 242 | UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
| 243 | if (!pDocument) |
| 244 | return nullptr; |
| 245 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 246 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 247 | // If the CPDFXFA_Context has a FormFillEnvironment already then we've done |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 248 | // this and can just return the old Env. Otherwise, we'll end up setting a new |
| 249 | // environment into the XFADocument and, that could get weird. |
dsinclair | 655fcca | 2016-10-11 13:53:37 -0700 | [diff] [blame] | 250 | if (pDocument->GetFormFillEnv()) |
| 251 | return pDocument->GetFormFillEnv(); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 252 | #endif |
| 253 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 254 | auto pFormFillEnv = |
| 255 | pdfium::MakeUnique<CPDFSDK_FormFillEnvironment>(pDocument, formInfo); |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 256 | |
| 257 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 258 | pDocument->SetFormFillEnv(pFormFillEnv.get()); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 259 | #endif // PDF_ENABLE_XFA |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 260 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 261 | return pFormFillEnv.release(); // Caller takes ownership. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 264 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 266 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 267 | HandleToCPDFSDKEnvironment(hHandle); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 268 | if (!pFormFillEnv) |
| 269 | return; |
dsinclair | a939bfe | 2016-09-22 13:18:45 -0700 | [diff] [blame] | 270 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 271 | #ifdef PDF_ENABLE_XFA |
dsinclair | 2116105 | 2016-10-05 15:46:15 -0700 | [diff] [blame] | 272 | // Reset the focused annotations and remove the SDK document from the |
| 273 | // XFA document. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 274 | pFormFillEnv->ClearAllFocusedAnnots(); |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 275 | // If the document was closed first, it's possible the XFA document |
| 276 | // is now a nullptr. |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 277 | if (pFormFillEnv->GetXFAContext()) |
| 278 | pFormFillEnv->GetXFAContext()->SetFormFillEnv(nullptr); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 279 | #endif // PDF_ENABLE_XFA |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 280 | delete pFormFillEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 283 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 284 | FPDF_PAGE page, |
| 285 | int modifier, |
| 286 | double page_x, |
| 287 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 289 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 290 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 291 | return pPageView->OnMouseMove(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Lei Zhang | 63b0126 | 2017-08-31 08:54:46 -0700 | [diff] [blame] | 294 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnFocus(FPDF_FORMHANDLE hHandle, |
| 295 | FPDF_PAGE page, |
| 296 | int modifier, |
| 297 | double page_x, |
| 298 | double page_y) { |
| 299 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 300 | if (!pPageView) |
| 301 | return false; |
| 302 | return pPageView->OnFocus(CFX_PointF(page_x, page_y), modifier); |
| 303 | } |
| 304 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 305 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, |
| 306 | FPDF_PAGE page, |
| 307 | int modifier, |
| 308 | double page_x, |
| 309 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 311 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 312 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 313 | return pPageView->OnLButtonDown(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 316 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| 317 | FPDF_PAGE page, |
| 318 | int modifier, |
| 319 | double page_x, |
| 320 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 321 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 322 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 323 | return false; |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 324 | return pPageView->OnLButtonUp(CFX_PointF(page_x, page_y), modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 327 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 328 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 329 | FPDF_PAGE page, |
| 330 | int modifier, |
| 331 | double page_x, |
| 332 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 334 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 335 | return false; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 336 | return pPageView->OnRButtonDown(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 339 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 340 | FPDF_PAGE page, |
| 341 | int modifier, |
| 342 | double page_x, |
| 343 | double page_y) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 345 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 346 | return false; |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 347 | return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 348 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 349 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 350 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 351 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| 352 | FPDF_PAGE page, |
| 353 | int nKeyCode, |
| 354 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 356 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 357 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | return pPageView->OnKeyDown(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 361 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, |
| 362 | FPDF_PAGE page, |
| 363 | int nKeyCode, |
| 364 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 365 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 366 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 367 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 368 | return pPageView->OnKeyUp(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 371 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnChar(FPDF_FORMHANDLE hHandle, |
| 372 | FPDF_PAGE page, |
| 373 | int nChar, |
| 374 | int modifier) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 375 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 376 | if (!pPageView) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 377 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 378 | return pPageView->OnChar(nChar, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 381 | FPDF_EXPORT unsigned long FPDF_CALLCONV |
| 382 | FORM_GetSelectedText(FPDF_FORMHANDLE hHandle, |
| 383 | FPDF_PAGE page, |
| 384 | void* buffer, |
| 385 | unsigned long buflen) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 386 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 387 | if (!pPageView) |
| 388 | return 0; |
| 389 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 390 | WideString wide_str_form_text = pPageView->GetSelectedText(); |
| 391 | ByteString encoded_form_text = wide_str_form_text.UTF16LE_Encode(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 392 | unsigned long form_text_len = encoded_form_text.GetLength(); |
| 393 | |
| 394 | if (buffer && buflen >= form_text_len) |
| 395 | memcpy(buffer, encoded_form_text.c_str(), form_text_len); |
| 396 | |
| 397 | return form_text_len; |
| 398 | } |
| 399 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 400 | FPDF_EXPORT void FPDF_CALLCONV FORM_ReplaceSelection(FPDF_FORMHANDLE hHandle, |
| 401 | FPDF_PAGE page, |
| 402 | FPDF_WIDESTRING wsText) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 403 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 404 | if (!pPageView) |
| 405 | return; |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 406 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 407 | FX_STRSIZE len = WideString::WStringLength(wsText); |
| 408 | WideString wide_str_text = WideString::FromUTF16LE(wsText, len); |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 409 | |
| 410 | pPageView->ReplaceSelection(wide_str_text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 413 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 414 | FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 415 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 416 | HandleToCPDFSDKEnvironment(hHandle); |
| 417 | if (!pFormFillEnv) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 418 | return false; |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 419 | return pFormFillEnv->KillFocusAnnot(0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 422 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 423 | FPDF_BITMAP bitmap, |
| 424 | FPDF_PAGE page, |
| 425 | int start_x, |
| 426 | int start_y, |
| 427 | int size_x, |
| 428 | int size_y, |
| 429 | int rotate, |
| 430 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 431 | FFLCommon(hHandle, bitmap, nullptr, page, start_x, start_y, size_x, size_y, |
| 432 | rotate, flags); |
| 433 | } |
| 434 | |
| 435 | #ifdef _SKIA_SUPPORT_ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 436 | FPDF_EXPORT void FPDF_CALLCONV FPDF_FFLRecord(FPDF_FORMHANDLE hHandle, |
| 437 | FPDF_RECORDER recorder, |
| 438 | FPDF_PAGE page, |
| 439 | int start_x, |
| 440 | int start_y, |
| 441 | int size_x, |
| 442 | int size_y, |
| 443 | int rotate, |
| 444 | int flags) { |
Cary Clark | 399be5b | 2016-03-14 16:51:29 -0400 | [diff] [blame] | 445 | FFLCommon(hHandle, nullptr, recorder, page, start_x, start_y, size_x, size_y, |
| 446 | rotate, flags); |
| 447 | } |
| 448 | #endif |
| 449 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 450 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 451 | FPDF_EXPORT void FPDF_CALLCONV FPDF_Widget_Undo(FPDF_DOCUMENT document, |
| 452 | FPDF_WIDGET hWidget) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 453 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 455 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 456 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 457 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 458 | pContext->GetDocType() != XFA_DocType::Static) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | return; |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 460 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 461 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 462 | static_cast<CXFA_FFWidget*>(hWidget)->Undo(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 463 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 464 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 465 | FPDF_EXPORT void FPDF_CALLCONV FPDF_Widget_Redo(FPDF_DOCUMENT document, |
| 466 | FPDF_WIDGET hWidget) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 467 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 469 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 470 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 471 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 472 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 474 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 475 | static_cast<CXFA_FFWidget*>(hWidget)->Redo(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 478 | FPDF_EXPORT void FPDF_CALLCONV FPDF_Widget_SelectAll(FPDF_DOCUMENT document, |
| 479 | FPDF_WIDGET hWidget) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 480 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 482 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 483 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 484 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 485 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 487 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 488 | static_cast<CXFA_FFWidget*>(hWidget)->SelectAll(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 489 | } |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 490 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 491 | FPDF_EXPORT void FPDF_CALLCONV FPDF_Widget_Copy(FPDF_DOCUMENT document, |
| 492 | FPDF_WIDGET hWidget, |
| 493 | FPDF_WIDESTRING wsText, |
| 494 | FPDF_DWORD* size) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 495 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 497 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 498 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 499 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 500 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 501 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 502 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 503 | WideString wsCpText; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 504 | static_cast<CXFA_FFWidget*>(hWidget)->Copy(wsCpText); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 505 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 506 | ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 507 | uint32_t len = bsCpText.GetLength() / sizeof(unsigned short); |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 508 | if (!wsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | *size = len; |
| 510 | return; |
| 511 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 512 | |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 513 | uint32_t real_size = len < *size ? len : *size; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | if (real_size > 0) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 515 | memcpy((void*)wsText, |
| 516 | bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 517 | real_size * sizeof(unsigned short)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 519 | } |
| 520 | *size = real_size; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 521 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 522 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 523 | FPDF_EXPORT void FPDF_CALLCONV FPDF_Widget_Cut(FPDF_DOCUMENT document, |
| 524 | FPDF_WIDGET hWidget, |
| 525 | FPDF_WIDESTRING wsText, |
| 526 | FPDF_DWORD* size) { |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 527 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | return; |
thestig | befa450 | 2016-05-26 20:15:19 -0700 | [diff] [blame] | 529 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 530 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 531 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 532 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 533 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 534 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 535 | WideString wsCpText; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 536 | static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 537 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 538 | ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 539 | uint32_t len = bsCpText.GetLength() / sizeof(unsigned short); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 540 | if (!wsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | *size = len; |
| 542 | return; |
| 543 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 544 | |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 545 | uint32_t real_size = len < *size ? len : *size; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | if (real_size > 0) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 547 | memcpy((void*)wsText, |
| 548 | bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 549 | real_size * sizeof(unsigned short)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 551 | } |
| 552 | *size = real_size; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 553 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 554 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 555 | FPDF_EXPORT void FPDF_CALLCONV FPDF_Widget_Paste(FPDF_DOCUMENT document, |
| 556 | FPDF_WIDGET hWidget, |
| 557 | FPDF_WIDESTRING wsText, |
| 558 | FPDF_DWORD size) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 559 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 560 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 561 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 562 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 563 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 564 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 566 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 567 | WideString wstr = WideString::FromUTF16LE(wsText, size); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 568 | static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 569 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 570 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 571 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, |
| 573 | FPDF_WIDGET hWidget, |
| 574 | float x, |
| 575 | float y, |
| 576 | FPDF_BYTESTRING bsText) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 577 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 578 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 579 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 580 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 581 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 582 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 583 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 584 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 585 | CFX_PointF ptPopup; |
| 586 | ptPopup.x = x; |
| 587 | ptPopup.y = y; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 588 | ByteStringView bs(bsText); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 589 | static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 590 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 591 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 592 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 593 | FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, |
| 594 | FPDF_WIDGET hWidget, |
| 595 | float x, |
| 596 | float y, |
| 597 | FPDF_STRINGHANDLE* stringHandle) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 598 | if (!hWidget || !document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 599 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 600 | |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 601 | auto* pContext = static_cast<CPDFXFA_Context*>(document); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 602 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 603 | pContext->GetDocType() != XFA_DocType::Static) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 605 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 606 | CFX_PointF ptPopup; |
| 607 | ptPopup.x = x; |
| 608 | ptPopup.y = y; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 609 | auto sSuggestWords = pdfium::MakeUnique<std::vector<ByteString>>(); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 610 | static_cast<CXFA_FFWidget*>(hWidget)->GetSuggestWords(ptPopup, |
| 611 | sSuggestWords.get()); |
| 612 | |
| 613 | // Caller takes ownership. |
| 614 | *stringHandle = ToFPDFStringHandle(sSuggestWords.release()); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 615 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 616 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 617 | FPDF_EXPORT int FPDF_CALLCONV |
| 618 | FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 619 | std::vector<ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle); |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 620 | return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 621 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 622 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 623 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 624 | FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 625 | int index, |
| 626 | FPDF_BYTESTRING bsText, |
| 627 | FPDF_DWORD* size) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 628 | if (!sHandle || !size) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 629 | return false; |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 630 | |
| 631 | int count = FPDF_StringHandleCounts(sHandle); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 632 | if (index < 0 || index >= count) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 633 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 634 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 635 | std::vector<ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle); |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 636 | uint32_t len = (*sSuggestWords)[index].GetLength(); |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 637 | if (!bsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | *size = len; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 639 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | } |
| 641 | |
weili | 47ca692 | 2016-03-31 15:08:27 -0700 | [diff] [blame] | 642 | uint32_t real_size = len < *size ? len : *size; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | if (real_size > 0) |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 644 | memcpy((void*)bsText, (*sSuggestWords)[index].c_str(), real_size); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | *size = real_size; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 646 | return true; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 647 | } |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 648 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 649 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 651 | delete FromFPDFStringHandle(stringHandle); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 654 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 655 | FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, |
| 656 | FPDF_BYTESTRING bsText, |
| 657 | FPDF_DWORD size) { |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 658 | if (!stringHandle || !bsText || size == 0) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 659 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 660 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 661 | FromFPDFStringHandle(stringHandle)->push_back(ByteString(bsText, size)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 662 | return true; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 663 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 664 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 665 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 666 | FPDF_EXPORT void FPDF_CALLCONV |
| 667 | FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 668 | int fieldType, |
| 669 | unsigned long color) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 671 | pInterForm->SetHighlightColor(color, fieldType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 674 | FPDF_EXPORT void FPDF_CALLCONV |
| 675 | FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 677 | pInterForm->SetHighlightAlpha(alpha); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 680 | FPDF_EXPORT void FPDF_CALLCONV |
| 681 | FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 682 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 683 | pInterForm->RemoveAllHighLight(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 686 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 687 | FPDF_FORMHANDLE hHandle) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 689 | pPageView->SetValid(true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 692 | FPDF_EXPORT void FPDF_CALLCONV FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 693 | FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 694 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 695 | HandleToCPDFSDKEnvironment(hHandle); |
| 696 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 697 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 698 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 699 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 700 | if (!pPage) |
| 701 | return; |
| 702 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 703 | CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 704 | if (pPageView) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 705 | pPageView->SetValid(false); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 706 | // RemovePageView() takes care of the delete for us. |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 707 | pFormFillEnv->RemovePageView(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 711 | FPDF_EXPORT void FPDF_CALLCONV |
| 712 | FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 713 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 714 | HandleToCPDFSDKEnvironment(hHandle); |
| 715 | if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 716 | pFormFillEnv->ProcJavascriptFun(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 719 | FPDF_EXPORT void FPDF_CALLCONV |
| 720 | FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 721 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 722 | HandleToCPDFSDKEnvironment(hHandle); |
| 723 | if (pFormFillEnv && pFormFillEnv->IsJSInitiated()) |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 724 | pFormFillEnv->ProcOpenAction(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 727 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 728 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 729 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 730 | HandleToCPDFSDKEnvironment(hHandle); |
| 731 | if (!pFormFillEnv) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 732 | return; |
| 733 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 734 | CPDF_Document* pDoc = pFormFillEnv->GetPDFDocument(); |
Lei Zhang | 0158106 | 2017-08-30 14:19:26 -0700 | [diff] [blame] | 735 | const CPDF_Dictionary* pDict = pDoc->GetRoot(); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 736 | if (!pDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 738 | |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 739 | CPDF_AAction aa(pDict->GetDictFor("AA")); |
| 740 | auto type = static_cast<CPDF_AAction::AActionType>(aaType); |
| 741 | if (aa.ActionExist(type)) { |
| 742 | CPDF_Action action = aa.GetAction(type); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | CPDFSDK_ActionHandler* pActionHandler = |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 744 | HandleToCPDFSDKEnvironment(hHandle)->GetActionHandler(); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 745 | pActionHandler->DoAction_Document(action, type, pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 749 | FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, |
| 750 | FPDF_FORMHANDLE hHandle, |
| 751 | int aaType) { |
dsinclair | f3fbe83 | 2016-10-11 13:08:04 -0700 | [diff] [blame] | 752 | CPDFSDK_FormFillEnvironment* pFormFillEnv = |
| 753 | HandleToCPDFSDKEnvironment(hHandle); |
| 754 | if (!pFormFillEnv) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 755 | return; |
| 756 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 757 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 758 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 759 | if (!pPDFPage) |
| 760 | return; |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 761 | |
dsinclair | 7cbe68e | 2016-10-12 11:56:23 -0700 | [diff] [blame] | 762 | if (!pFormFillEnv->GetPageView(pPage, false)) |
tonikitoo | 401d4f2 | 2016-08-10 11:37:45 -0700 | [diff] [blame] | 763 | return; |
| 764 | |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 765 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); |
Tom Sepez | 4cb82ee | 2017-05-22 15:15:30 -0700 | [diff] [blame] | 766 | CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 767 | CPDF_AAction aa(pPageDict->GetDictFor("AA")); |
Lei Zhang | 1fed5a2 | 2017-06-01 11:52:22 -0700 | [diff] [blame] | 768 | CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN |
| 769 | ? CPDF_AAction::OpenPage |
| 770 | : CPDF_AAction::ClosePage; |
| 771 | if (aa.ActionExist(type)) { |
| 772 | CPDF_Action action = aa.GetAction(type); |
| 773 | pActionHandler->DoAction_Page(action, type, pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 774 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 775 | } |