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