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