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 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 9 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 10 | #include "../include/fpdfxfa/fpdfxfa_app.h" |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 11 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 12 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 13 | #endif |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 14 | #include "fpdfsdk/include/fsdk_define.h" |
| 15 | #include "fpdfsdk/include/fsdk_mgr.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 16 | #include "public/fpdfview.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 17 | #include "third_party/base/nonstd_unique_ptr.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 19 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) { |
| 22 | CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| 23 | return pEnv ? pEnv->GetSDKDocument() : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 24 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
| 27 | CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 28 | return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 29 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 32 | FPDF_PAGE page) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 33 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 34 | if (!pPage) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | return nullptr; |
Tom Sepez | 0b13398 | 2015-07-28 11:23:22 -0700 | [diff] [blame] | 36 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 37 | CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 38 | return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 39 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 40 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 41 | } // namespace |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 42 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 43 | DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 44 | FPDF_PAGE page, |
| 45 | double page_x, |
| 46 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 47 | if (!hHandle) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 48 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 49 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 50 | #ifndef PDF_ENABLE_XFA |
| 51 | if (!pPage) |
| 52 | return -1; |
| 53 | CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| 54 | CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
| 55 | pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); |
| 56 | if (!pFormCtrl) |
| 57 | return -1; |
| 58 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | if (pPage) { |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 60 | CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| 61 | CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
| 62 | pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); |
| 63 | if (!pFormCtrl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | return -1; |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 65 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 67 | if (!pFormField) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | |
| 70 | int nType = pFormField->GetFieldType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | return nType; |
| 72 | } |
| 73 | |
| 74 | IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView(); |
| 75 | if (pPageView) { |
| 76 | IXFA_WidgetHandler* pWidgetHandler = NULL; |
| 77 | IXFA_DocView* pDocView = pPageView->GetDocView(); |
| 78 | if (!pDocView) |
| 79 | return -1; |
| 80 | |
| 81 | pWidgetHandler = pDocView->GetWidgetHandler(); |
| 82 | if (!pWidgetHandler) |
| 83 | return -1; |
| 84 | |
| 85 | IXFA_Widget* pXFAAnnot = NULL; |
| 86 | IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator( |
| 87 | XFA_TRAVERSEWAY_Form, |
| 88 | XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType); |
| 89 | if (!pWidgetIterator) |
| 90 | return -1; |
| 91 | pXFAAnnot = pWidgetIterator->MoveToNext(); |
| 92 | while (pXFAAnnot) { |
| 93 | CFX_RectF rcBBox; |
| 94 | pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0); |
| 95 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, |
| 96 | rcBBox.left + rcBBox.width, |
| 97 | rcBBox.top + rcBBox.height); |
| 98 | rcWidget.left -= 1.0f; |
| 99 | rcWidget.right += 1.0f; |
| 100 | rcWidget.bottom -= 1.0f; |
| 101 | rcWidget.top += 1.0f; |
| 102 | |
| 103 | if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), |
| 104 | static_cast<FX_FLOAT>(page_y))) { |
| 105 | pWidgetIterator->Release(); |
| 106 | return FPDF_FORMFIELD_XFA; |
| 107 | } |
| 108 | pXFAAnnot = pWidgetIterator->MoveToNext(); |
| 109 | } |
| 110 | |
| 111 | pWidgetIterator->Release(); |
| 112 | } |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 113 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 115 | #ifndef PDF_ENABLE_XFA |
| 116 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
| 117 | return pFormField ? pFormField->GetFieldType() : -1; |
| 118 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 119 | return -1; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 120 | #endif |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 123 | DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 124 | FPDF_PAGE page, |
| 125 | double page_x, |
| 126 | double page_y) { |
| 127 | return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); |
| 128 | } |
| 129 | |
| 130 | DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| 131 | FPDF_PAGE page, |
| 132 | double page_x, |
| 133 | double page_y) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 134 | if (!hHandle) |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 135 | return -1; |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 136 | CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 137 | if (!pPage) |
| 138 | return -1; |
Lei Zhang | bdf72c3 | 2015-08-14 19:24:08 -0700 | [diff] [blame] | 139 | CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| 140 | int z_order = -1; |
| 141 | (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, |
| 142 | &z_order); |
| 143 | return z_order; |
| 144 | } |
| 145 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | DLLEXPORT FPDF_FORMHANDLE STDCALL |
| 147 | FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| 148 | FPDF_FORMFILLINFO* formInfo) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 149 | #ifndef PDF_ENABLE_XFA |
| 150 | const int kRequiredVersion = 1; |
| 151 | #else |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 152 | const int kRequiredVersion = 2; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 153 | #endif |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 154 | if (!formInfo || formInfo->version != kRequiredVersion) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 156 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 157 | UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
| 158 | if (!pDocument) |
| 159 | return nullptr; |
| 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 162 | #ifndef PDF_ENABLE_XFA |
| 163 | pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); |
| 164 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 166 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| 168 | pApp->AddFormFillEnv(pEnv); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 169 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | return pEnv; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | DLLEXPORT void STDCALL |
| 174 | FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| 175 | if (!hHandle) |
| 176 | return; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 177 | #ifndef PDF_ENABLE_XFA |
| 178 | |
| 179 | CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| 180 | if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
| 181 | pEnv->SetSDKDocument(NULL); |
| 182 | delete pSDKDoc; |
| 183 | } |
| 184 | delete pEnv; |
| 185 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 186 | CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| 187 | pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); |
| 188 | delete (CPDFDoc_Environment*)hHandle; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 189 | #endif |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| 193 | FPDF_PAGE page, |
| 194 | int modifier, |
| 195 | double page_x, |
| 196 | double page_y) { |
| 197 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 198 | if (!pPageView) |
| 199 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 200 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 202 | return pPageView->OnMouseMove(pt, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, |
| 206 | FPDF_PAGE page, |
| 207 | int modifier, |
| 208 | double page_x, |
| 209 | double page_y) { |
| 210 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 211 | if (!pPageView) |
| 212 | return FALSE; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 213 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 215 | return pPageView->OnLButtonDown(pt, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| 219 | FPDF_PAGE page, |
| 220 | int modifier, |
| 221 | double page_x, |
| 222 | double page_y) { |
| 223 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 224 | if (!pPageView) |
| 225 | return FALSE; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 226 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 228 | return pPageView->OnLButtonUp(pt, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 231 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 233 | FPDF_PAGE page, |
| 234 | int modifier, |
| 235 | double page_x, |
| 236 | double page_y) { |
| 237 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 238 | if (!pPageView) |
| 239 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 240 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 241 | CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 242 | return pPageView->OnRButtonDown(pt, modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 246 | FPDF_PAGE page, |
| 247 | int modifier, |
| 248 | double page_x, |
| 249 | double page_y) { |
| 250 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 251 | if (!pPageView) |
| 252 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 255 | return pPageView->OnRButtonUp(pt, modifier); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 258 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| 260 | FPDF_PAGE page, |
| 261 | int nKeyCode, |
| 262 | int modifier) { |
| 263 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 264 | if (!pPageView) |
| 265 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 266 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | return pPageView->OnKeyDown(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, |
| 271 | FPDF_PAGE page, |
| 272 | int nKeyCode, |
| 273 | int modifier) { |
| 274 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 275 | if (!pPageView) |
| 276 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 277 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 278 | return pPageView->OnKeyUp(nKeyCode, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, |
| 282 | FPDF_PAGE page, |
| 283 | int nChar, |
| 284 | int modifier) { |
| 285 | CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 286 | if (!pPageView) |
| 287 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | return pPageView->OnChar(nChar, modifier); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 292 | DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) { |
| 293 | CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 294 | if (!pSDKDoc) |
| 295 | return FALSE; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 296 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | return pSDKDoc->KillFocusAnnot(0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 300 | DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 301 | FPDF_BITMAP bitmap, |
| 302 | FPDF_PAGE page, |
| 303 | int start_x, |
| 304 | int start_y, |
| 305 | int size_x, |
| 306 | int size_y, |
| 307 | int rotate, |
| 308 | int flags) { |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 309 | if (!hHandle) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | return; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 311 | |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 312 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 313 | if (!pPage) |
| 314 | return; |
| 315 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 316 | #ifndef PDF_ENABLE_XFA |
| 317 | CPDF_RenderOptions options; |
| 318 | if (flags & FPDF_LCD_TEXT) |
| 319 | options.m_Flags |= RENDER_CLEARTYPE; |
| 320 | else |
| 321 | options.m_Flags &= ~RENDER_CLEARTYPE; |
| 322 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | CPDFXFA_Document* pDocument = pPage->GetDocument(); |
| 324 | if (!pDocument) |
| 325 | return; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 326 | #endif |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 327 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 328 | #ifndef PDF_ENABLE_XFA |
| 329 | // Grayscale output |
| 330 | if (flags & FPDF_GRAYSCALE) { |
| 331 | options.m_ColorMode = RENDER_COLOR_GRAY; |
| 332 | options.m_ForeColor = 0; |
| 333 | options.m_BackColor = 0xffffff; |
| 334 | } |
| 335 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); |
| 337 | if (!pPDFDoc) |
| 338 | return; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 339 | #endif |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 340 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 341 | #ifndef PDF_ENABLE_XFA |
| 342 | options.m_AddFlags = flags >> 8; |
| 343 | options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument); |
| 344 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 345 | CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| 346 | CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); |
| 347 | if (!pFXDoc) |
| 348 | return; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 349 | #endif |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 350 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 351 | CFX_AffineMatrix matrix; |
| 352 | pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 353 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | FX_RECT clip; |
| 355 | clip.left = start_x; |
| 356 | clip.right = start_x + size_x; |
| 357 | clip.top = start_y; |
| 358 | clip.bottom = start_y + size_y; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 359 | |
| 360 | #ifdef _SKIA_SUPPORT_ |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 361 | nonstd::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 362 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 364 | #endif |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 365 | #ifdef PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 366 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | if (!pDevice) |
| 368 | return; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 369 | #endif |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | pDevice->Attach((CFX_DIBitmap*)bitmap); |
| 371 | pDevice->SaveState(); |
| 372 | pDevice->SetClip_Rect(&clip); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 373 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 374 | #ifndef PDF_ENABLE_XFA |
| 375 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
| 376 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
| 377 | #else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 378 | CPDF_RenderOptions options; |
| 379 | if (flags & FPDF_LCD_TEXT) |
| 380 | options.m_Flags |= RENDER_CLEARTYPE; |
| 381 | else |
| 382 | options.m_Flags &= ~RENDER_CLEARTYPE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 383 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | // Grayscale output |
| 385 | if (flags & FPDF_GRAYSCALE) { |
| 386 | options.m_ColorMode = RENDER_COLOR_GRAY; |
| 387 | options.m_ForeColor = 0; |
| 388 | options.m_BackColor = 0xffffff; |
| 389 | } |
| 390 | options.m_AddFlags = flags >> 8; |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 391 | options.m_pOCContext = new CPDF_OCContext(pPDFDoc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 392 | |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 393 | if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage)) |
Lei Zhang | f0e2e1b | 2015-11-02 13:27:54 -0800 | [diff] [blame] | 394 | pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 395 | #endif |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 396 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 397 | pDevice->RestoreState(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 398 | delete options.m_pOCContext; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 399 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | options.m_pOCContext = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 401 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, |
| 403 | FPDF_WIDGET hWidget) { |
| 404 | if (NULL == hWidget || NULL == document) |
| 405 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 406 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 408 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 409 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 410 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 411 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 412 | IXFA_MenuHandler* pXFAMenuHander = |
| 413 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 414 | if (pXFAMenuHander == NULL) |
| 415 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 416 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | pXFAMenuHander->Undo((IXFA_Widget*)hWidget); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 418 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, |
| 420 | FPDF_WIDGET hWidget) { |
| 421 | if (NULL == hWidget || NULL == document) |
| 422 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 423 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 425 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 426 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 427 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 428 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 429 | IXFA_MenuHandler* pXFAMenuHander = |
| 430 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 431 | if (pXFAMenuHander == NULL) |
| 432 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 433 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 434 | pXFAMenuHander->Redo((IXFA_Widget*)hWidget); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, |
| 438 | FPDF_WIDGET hWidget) { |
| 439 | if (NULL == hWidget || NULL == document) |
| 440 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 441 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 443 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 444 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 445 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 446 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 447 | IXFA_MenuHandler* pXFAMenuHander = |
| 448 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 449 | if (pXFAMenuHander == NULL) |
| 450 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 451 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | pXFAMenuHander->SelectAll((IXFA_Widget*)hWidget); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 453 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, |
| 455 | FPDF_WIDGET hWidget, |
| 456 | FPDF_WIDESTRING wsText, |
| 457 | FPDF_DWORD* size) { |
| 458 | if (NULL == hWidget || NULL == document) |
| 459 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 460 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 462 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 463 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 464 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 465 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | IXFA_MenuHandler* pXFAMenuHander = |
| 467 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 468 | if (pXFAMenuHander == NULL) |
| 469 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 470 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | CFX_WideString wsCpText; |
| 472 | pXFAMenuHander->Copy((IXFA_Widget*)hWidget, wsCpText); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 473 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
| 475 | int len = bsCpText.GetLength() / sizeof(unsigned short); |
| 476 | if (wsText == NULL) { |
| 477 | *size = len; |
| 478 | return; |
| 479 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 480 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | int real_size = len < *size ? len : *size; |
| 482 | if (real_size > 0) { |
| 483 | FXSYS_memcpy((void*)wsText, |
| 484 | bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 485 | real_size * sizeof(unsigned short)); |
| 486 | bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 487 | } |
| 488 | *size = real_size; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 489 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, |
| 491 | FPDF_WIDGET hWidget, |
| 492 | FPDF_WIDESTRING wsText, |
| 493 | FPDF_DWORD* size) { |
| 494 | if (NULL == hWidget || NULL == document) |
| 495 | return; |
| 496 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 497 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 498 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 499 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 500 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 501 | IXFA_MenuHandler* pXFAMenuHander = |
| 502 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 503 | if (pXFAMenuHander == NULL) |
| 504 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 505 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | CFX_WideString wsCpText; |
| 507 | pXFAMenuHander->Cut((IXFA_Widget*)hWidget, wsCpText); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 508 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
| 510 | int len = bsCpText.GetLength() / sizeof(unsigned short); |
| 511 | if (wsText == NULL) { |
| 512 | *size = len; |
| 513 | return; |
| 514 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 515 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 516 | int real_size = len < *size ? len : *size; |
| 517 | if (real_size > 0) { |
| 518 | FXSYS_memcpy((void*)wsText, |
| 519 | bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 520 | real_size * sizeof(unsigned short)); |
| 521 | bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 522 | } |
| 523 | *size = real_size; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 524 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, |
| 526 | FPDF_WIDGET hWidget, |
| 527 | FPDF_WIDESTRING wsText, |
| 528 | FPDF_DWORD size) { |
| 529 | if (NULL == hWidget || NULL == document) |
| 530 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 531 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 533 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 534 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 535 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 536 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | IXFA_MenuHandler* pXFAMenuHander = |
| 538 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 539 | if (pXFAMenuHander == NULL) |
| 540 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 541 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 542 | CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); |
| 543 | pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 544 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 545 | DLLEXPORT void STDCALL |
| 546 | FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, |
| 547 | FPDF_WIDGET hWidget, |
| 548 | float x, |
| 549 | float y, |
| 550 | FPDF_BYTESTRING bsText) { |
| 551 | if (NULL == hWidget || NULL == document) |
| 552 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 553 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 554 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 555 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 556 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 557 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 558 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | IXFA_MenuHandler* pXFAMenuHander = |
| 560 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 561 | if (pXFAMenuHander == NULL) |
| 562 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 563 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | CFX_PointF ptPopup; |
| 565 | ptPopup.x = x; |
| 566 | ptPopup.y = y; |
| 567 | CFX_ByteStringC bs(bsText); |
| 568 | pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 569 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | DLLEXPORT void STDCALL |
| 571 | FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, |
| 572 | FPDF_WIDGET hWidget, |
| 573 | float x, |
| 574 | float y, |
| 575 | FPDF_STRINGHANDLE* stringHandle) { |
| 576 | if (NULL == hWidget || NULL == document) |
| 577 | return; |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 578 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 580 | if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 581 | pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 582 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 583 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 584 | IXFA_MenuHandler* pXFAMenuHander = |
| 585 | CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 586 | if (pXFAMenuHander == NULL) |
| 587 | return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 588 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 589 | CFX_ByteStringArray* sSuggestWords = new CFX_ByteStringArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 590 | CFX_PointF ptPopup; |
| 591 | ptPopup.x = x; |
| 592 | ptPopup.y = y; |
| 593 | pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup, |
| 594 | *sSuggestWords); |
| 595 | *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 596 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 597 | DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle) { |
| 598 | if (stringHandle == NULL) |
| 599 | return -1; |
| 600 | CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; |
| 601 | return sSuggestWords->GetSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 602 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 603 | DLLEXPORT FPDF_BOOL STDCALL |
| 604 | FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle, |
| 605 | int index, |
| 606 | FPDF_BYTESTRING bsText, |
| 607 | FPDF_DWORD* size) { |
| 608 | if (stringHandle == NULL || size == NULL) |
| 609 | return FALSE; |
| 610 | int count = FPDF_StringHandleCounts(stringHandle); |
| 611 | if (index < 0 || index >= count) |
| 612 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 613 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle; |
| 615 | int len = sSuggestWords[index].GetLength(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 616 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | if (bsText == NULL) { |
| 618 | *size = len; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 619 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | int real_size = len < *size ? len : *size; |
| 623 | if (real_size > 0) |
| 624 | FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]), |
| 625 | real_size); |
| 626 | *size = real_size; |
| 627 | |
| 628 | return TRUE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 629 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | DLLEXPORT void STDCALL |
| 631 | FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { |
| 632 | if (stringHandle == NULL) |
| 633 | return; |
| 634 | CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; |
| 635 | delete sSuggestWords; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | DLLEXPORT FPDF_BOOL STDCALL |
| 639 | FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, |
| 640 | FPDF_BYTESTRING bsText, |
| 641 | FPDF_DWORD size) { |
| 642 | if (stringHandle == NULL || bsText == NULL || size <= 0) |
| 643 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 644 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle; |
| 646 | CFX_ByteString bsStr(bsText, size); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 647 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | stringArr->Add(bsStr); |
| 649 | return TRUE; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 650 | #endif |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 651 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 652 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 653 | DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
| 654 | int fieldType, |
| 655 | unsigned long color) { |
| 656 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 657 | pInterForm->SetHighlightColor(color, fieldType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 660 | DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, |
| 661 | unsigned char alpha) { |
| 662 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 663 | pInterForm->SetHighlightAlpha(alpha); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) { |
| 667 | if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
| 668 | pInterForm->RemoveAllHighLight(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 671 | DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 672 | FPDF_FORMHANDLE hHandle) { |
| 673 | if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
| 674 | pPageView->SetValid(TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 677 | DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 678 | FPDF_FORMHANDLE hHandle) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 679 | if (!hHandle) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 680 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 681 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 682 | CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); |
| 683 | if (!pSDKDoc) |
| 684 | return; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 685 | |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 686 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 687 | if (!pPage) |
| 688 | return; |
| 689 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); |
| 691 | if (pPageView) { |
| 692 | pPageView->SetValid(FALSE); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 693 | // RemovePageView() takes care of the delete for us. |
| 694 | pSDKDoc->RemovePageView(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
| 698 | DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
| 699 | CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 700 | if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated()) |
| 701 | pSDKDoc->ProcJavascriptFun(); |
| 702 | } |
| 703 | |
| 704 | DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) { |
| 705 | CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 706 | if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated()) |
| 707 | pSDKDoc->ProcOpenAction(); |
| 708 | } |
| 709 | |
| 710 | DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, |
| 711 | int aaType) { |
| 712 | CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 713 | if (!pSDKDoc) |
| 714 | return; |
| 715 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 716 | CPDF_Document* pDoc = pSDKDoc->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | CPDF_Dictionary* pDic = pDoc->GetRoot(); |
| 718 | if (!pDic) |
| 719 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 720 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | CPDF_AAction aa = pDic->GetDict(FX_BSTRC("AA")); |
| 722 | if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) { |
| 723 | CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType); |
| 724 | CPDFSDK_ActionHandler* pActionHandler = |
| 725 | ((CPDFDoc_Environment*)hHandle)->GetActionHander(); |
| 726 | ASSERT(pActionHandler != NULL); |
| 727 | pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
| 728 | pSDKDoc); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, |
| 733 | FPDF_FORMHANDLE hHandle, |
| 734 | int aaType) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 735 | if (!hHandle) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | return; |
| 737 | CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 738 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
| 739 | CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 740 | if (!pPDFPage) |
| 741 | return; |
| 742 | if (pSDKDoc->GetPageView(pPage, FALSE)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); |
| 744 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 745 | CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 746 | CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA")); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | if (FPDFPAGE_AACTION_OPEN == aaType) { |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 748 | if (aa.ActionExist(CPDF_AAction::OpenPage)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 749 | CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 750 | pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
| 751 | } |
| 752 | } else { |
Tom Sepez | de4791d | 2015-10-30 12:13:10 -0700 | [diff] [blame] | 753 | if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 754 | CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 755 | pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
| 756 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 757 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |