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