blob: 95defc5da4034d6940dc5939f3b03c6f246ebe74 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_formfill.h"
8
Tom Sepez51da0932015-11-25 16:05:49 -08009#ifdef PDF_ENABLE_XFA
Lei Zhang8241df72015-11-06 14:38:48 -080010#include "../include/fpdfxfa/fpdfxfa_app.h"
Tom Sepezdfbf8e72015-10-14 14:17:26 -070011#include "../include/fpdfxfa/fpdfxfa_doc.h"
Bo Xufdc00a72014-10-28 23:03:33 -070012#include "../include/fpdfxfa/fpdfxfa_page.h"
Tom Sepez51da0932015-11-25 16:05:49 -080013#endif
Lei Zhangbde53d22015-11-12 22:21:30 -080014#include "fpdfsdk/include/fsdk_define.h"
15#include "fpdfsdk/include/fsdk_mgr.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080016#include "public/fpdfview.h"
Lei Zhang8241df72015-11-06 14:38:48 -080017#include "third_party/base/nonstd_unique_ptr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Tom Sepezdcbc02f2015-07-17 09:16:17 -070019namespace {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) {
22 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
23 return pEnv ? pEnv->GetSDKDocument() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070024}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) {
27 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
28 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070029}
Bo Xufdc00a72014-10-28 23:03:33 -070030
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle,
32 FPDF_PAGE page) {
Tom Sepez540c4362015-11-24 13:33:57 -080033 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
34 if (!pPage)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 return nullptr;
Tom Sepez0b133982015-07-28 11:23:22 -070036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
Tom Sepez540c4362015-11-24 13:33:57 -080038 return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070039}
Bo Xufdc00a72014-10-28 23:03:33 -070040
Tom Sepezdcbc02f2015-07-17 09:16:17 -070041} // namespace
Bo Xufdc00a72014-10-28 23:03:33 -070042
Lei Zhangbdf72c32015-08-14 19:24:08 -070043DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
44 FPDF_PAGE page,
45 double page_x,
46 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -070047 if (!hHandle)
Tom Sepezdcbc02f2015-07-17 09:16:17 -070048 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -070049 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
Tom Sepez51da0932015-11-25 16:05:49 -080050#ifndef PDF_ENABLE_XFA
51 if (!pPage)
52 return -1;
53 CPDF_InterForm interform(pPage->m_pDocument, FALSE);
54 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
55 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr);
56 if (!pFormCtrl)
57 return -1;
58#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 if (pPage) {
Lei Zhangbdf72c32015-08-14 19:24:08 -070060 CPDF_InterForm interform(pPage->m_pDocument, FALSE);
61 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(
62 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr);
63 if (!pFormCtrl)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 return -1;
Lei Zhangbdf72c32015-08-14 19:24:08 -070065
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 CPDF_FormField* pFormField = pFormCtrl->GetField();
Lei Zhangbdf72c32015-08-14 19:24:08 -070067 if (!pFormField)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069
70 int nType = pFormField->GetFieldType();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 return nType;
72 }
73
74 IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView();
75 if (pPageView) {
76 IXFA_WidgetHandler* pWidgetHandler = NULL;
77 IXFA_DocView* pDocView = pPageView->GetDocView();
78 if (!pDocView)
79 return -1;
80
81 pWidgetHandler = pDocView->GetWidgetHandler();
82 if (!pWidgetHandler)
83 return -1;
84
85 IXFA_Widget* pXFAAnnot = NULL;
86 IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator(
87 XFA_TRAVERSEWAY_Form,
88 XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType);
89 if (!pWidgetIterator)
90 return -1;
91 pXFAAnnot = pWidgetIterator->MoveToNext();
92 while (pXFAAnnot) {
93 CFX_RectF rcBBox;
94 pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0);
95 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top,
96 rcBBox.left + rcBBox.width,
97 rcBBox.top + rcBBox.height);
98 rcWidget.left -= 1.0f;
99 rcWidget.right += 1.0f;
100 rcWidget.bottom -= 1.0f;
101 rcWidget.top += 1.0f;
102
103 if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x),
104 static_cast<FX_FLOAT>(page_y))) {
105 pWidgetIterator->Release();
106 return FPDF_FORMFIELD_XFA;
107 }
108 pXFAAnnot = pWidgetIterator->MoveToNext();
109 }
110
111 pWidgetIterator->Release();
112 }
Tom Sepez51da0932015-11-25 16:05:49 -0800113#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114
Tom Sepez51da0932015-11-25 16:05:49 -0800115#ifndef PDF_ENABLE_XFA
116 CPDF_FormField* pFormField = pFormCtrl->GetField();
117 return pFormField ? pFormField->GetFieldType() : -1;
118#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 return -1;
Tom Sepez51da0932015-11-25 16:05:49 -0800120#endif
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121}
122
Lei Zhangbdf72c32015-08-14 19:24:08 -0700123DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
124 FPDF_PAGE page,
125 double page_x,
126 double page_y) {
127 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y);
128}
129
130DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle,
131 FPDF_PAGE page,
132 double page_x,
133 double page_y) {
Tom Sepezdb0be962015-10-16 14:00:21 -0700134 if (!hHandle)
Lei Zhangbdf72c32015-08-14 19:24:08 -0700135 return -1;
Tom Sepezdb0be962015-10-16 14:00:21 -0700136 CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
137 if (!pPage)
138 return -1;
Lei Zhangbdf72c32015-08-14 19:24:08 -0700139 CPDF_InterForm interform(pPage->m_pDocument, FALSE);
140 int z_order = -1;
141 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y,
142 &z_order);
143 return z_order;
144}
145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146DLLEXPORT FPDF_FORMHANDLE STDCALL
147FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
148 FPDF_FORMFILLINFO* formInfo) {
Tom Sepez51da0932015-11-25 16:05:49 -0800149#ifndef PDF_ENABLE_XFA
150 const int kRequiredVersion = 1;
151#else
Tom Sepez540c4362015-11-24 13:33:57 -0800152 const int kRequiredVersion = 2;
Tom Sepez51da0932015-11-25 16:05:49 -0800153#endif
Tom Sepez540c4362015-11-24 13:33:57 -0800154 if (!formInfo || formInfo->version != kRequiredVersion)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Tom Sepez540c4362015-11-24 13:33:57 -0800157 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document);
158 if (!pDocument)
159 return nullptr;
160
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo);
Tom Sepez51da0932015-11-25 16:05:49 -0800162#ifndef PDF_ENABLE_XFA
163 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv));
164#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv));
Bo Xufdc00a72014-10-28 23:03:33 -0700166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
168 pApp->AddFormFillEnv(pEnv);
Tom Sepez51da0932015-11-25 16:05:49 -0800169#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 return pEnv;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171}
172
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173DLLEXPORT void STDCALL
174FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
175 if (!hHandle)
176 return;
Tom Sepez51da0932015-11-25 16:05:49 -0800177#ifndef PDF_ENABLE_XFA
178
179 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
180 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) {
181 pEnv->SetSDKDocument(NULL);
182 delete pSDKDoc;
183 }
184 delete pEnv;
185#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
187 pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle);
188 delete (CPDFDoc_Environment*)hHandle;
Tom Sepez51da0932015-11-25 16:05:49 -0800189#endif
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190}
191
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle,
193 FPDF_PAGE page,
194 int modifier,
195 double page_x,
196 double page_y) {
197 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
198 if (!pPageView)
199 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700200
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
202 return pPageView->OnMouseMove(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203}
204
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle,
206 FPDF_PAGE page,
207 int modifier,
208 double page_x,
209 double page_y) {
210 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
211 if (!pPageView)
212 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700213
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
215 return pPageView->OnLButtonDown(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216}
217
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle,
219 FPDF_PAGE page,
220 int modifier,
221 double page_x,
222 double page_y) {
223 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
224 if (!pPageView)
225 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700226
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
228 return pPageView->OnLButtonUp(pt, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
Tom Sepez51da0932015-11-25 16:05:49 -0800231#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
233 FPDF_PAGE page,
234 int modifier,
235 double page_x,
236 double page_y) {
237 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
238 if (!pPageView)
239 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700240
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
242 return pPageView->OnRButtonDown(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700243}
244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
246 FPDF_PAGE page,
247 int modifier,
248 double page_x,
249 double page_y) {
250 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
251 if (!pPageView)
252 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
255 return pPageView->OnRButtonUp(pt, modifier);
Bo Xufdc00a72014-10-28 23:03:33 -0700256}
257
Tom Sepez51da0932015-11-25 16:05:49 -0800258#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
260 FPDF_PAGE page,
261 int nKeyCode,
262 int modifier) {
263 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
264 if (!pPageView)
265 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700266
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 return pPageView->OnKeyDown(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700268}
269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle,
271 FPDF_PAGE page,
272 int nKeyCode,
273 int modifier) {
274 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
275 if (!pPageView)
276 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 return pPageView->OnKeyUp(nKeyCode, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279}
280
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle,
282 FPDF_PAGE page,
283 int nChar,
284 int modifier) {
285 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page);
286 if (!pPageView)
287 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700288
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 return pPageView->OnChar(nChar, modifier);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290}
291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle) {
293 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
294 if (!pSDKDoc)
295 return FALSE;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700296
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 return pSDKDoc->KillFocusAnnot(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298}
299
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle,
301 FPDF_BITMAP bitmap,
302 FPDF_PAGE page,
303 int start_x,
304 int start_y,
305 int size_x,
306 int size_y,
307 int rotate,
308 int flags) {
Tom Sepez1b246282015-11-25 15:15:31 -0800309 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 return;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700311
Tom Sepez1b246282015-11-25 15:15:31 -0800312 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
313 if (!pPage)
314 return;
315
Tom Sepez51da0932015-11-25 16:05:49 -0800316#ifndef PDF_ENABLE_XFA
317 CPDF_RenderOptions options;
318 if (flags & FPDF_LCD_TEXT)
319 options.m_Flags |= RENDER_CLEARTYPE;
320 else
321 options.m_Flags &= ~RENDER_CLEARTYPE;
322#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 CPDFXFA_Document* pDocument = pPage->GetDocument();
324 if (!pDocument)
325 return;
Tom Sepez51da0932015-11-25 16:05:49 -0800326#endif
Tom Sepez1b246282015-11-25 15:15:31 -0800327
Tom Sepez51da0932015-11-25 16:05:49 -0800328#ifndef PDF_ENABLE_XFA
329 // Grayscale output
330 if (flags & FPDF_GRAYSCALE) {
331 options.m_ColorMode = RENDER_COLOR_GRAY;
332 options.m_ForeColor = 0;
333 options.m_BackColor = 0xffffff;
334 }
335#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc();
337 if (!pPDFDoc)
338 return;
Tom Sepez51da0932015-11-25 16:05:49 -0800339#endif
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700340
Tom Sepez51da0932015-11-25 16:05:49 -0800341#ifndef PDF_ENABLE_XFA
342 options.m_AddFlags = flags >> 8;
343 options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument);
344#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
346 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument();
347 if (!pFXDoc)
348 return;
Tom Sepez51da0932015-11-25 16:05:49 -0800349#endif
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700350
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 CFX_AffineMatrix matrix;
352 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 FX_RECT clip;
355 clip.left = start_x;
356 clip.right = start_x + size_x;
357 clip.top = start_y;
358 clip.bottom = start_y + size_y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359
360#ifdef _SKIA_SUPPORT_
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 nonstd::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363 nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364#endif
Tom Sepez51da0932015-11-25 16:05:49 -0800365#ifdef PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 if (!pDevice)
368 return;
Tom Sepez51da0932015-11-25 16:05:49 -0800369#endif
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 pDevice->Attach((CFX_DIBitmap*)bitmap);
371 pDevice->SaveState();
372 pDevice->SetClip_Rect(&clip);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700373
Tom Sepez51da0932015-11-25 16:05:49 -0800374#ifndef PDF_ENABLE_XFA
375 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
376 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
377#else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378 CPDF_RenderOptions options;
379 if (flags & FPDF_LCD_TEXT)
380 options.m_Flags |= RENDER_CLEARTYPE;
381 else
382 options.m_Flags &= ~RENDER_CLEARTYPE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384 // Grayscale output
385 if (flags & FPDF_GRAYSCALE) {
386 options.m_ColorMode = RENDER_COLOR_GRAY;
387 options.m_ForeColor = 0;
388 options.m_BackColor = 0xffffff;
389 }
390 options.m_AddFlags = flags >> 8;
Tom Sepezae51c812015-08-05 12:34:06 -0700391 options.m_pOCContext = new CPDF_OCContext(pPDFDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
Tom Sepez1b246282015-11-25 15:15:31 -0800393 if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800394 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
Tom Sepez51da0932015-11-25 16:05:49 -0800395#endif
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700396
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 pDevice->RestoreState();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 delete options.m_pOCContext;
Tom Sepez51da0932015-11-25 16:05:49 -0800399#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 options.m_pOCContext = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document,
403 FPDF_WIDGET hWidget) {
404 if (NULL == hWidget || NULL == document)
405 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700406
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
408 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
409 pDocument->GetDocType() != XFA_DOCTYPE_Static)
410 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700411
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 IXFA_MenuHandler* pXFAMenuHander =
413 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
414 if (pXFAMenuHander == NULL)
415 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700416
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 pXFAMenuHander->Undo((IXFA_Widget*)hWidget);
Bo Xufdc00a72014-10-28 23:03:33 -0700418}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document,
420 FPDF_WIDGET hWidget) {
421 if (NULL == hWidget || NULL == document)
422 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700423
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
425 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
426 pDocument->GetDocType() != XFA_DOCTYPE_Static)
427 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700428
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 IXFA_MenuHandler* pXFAMenuHander =
430 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
431 if (pXFAMenuHander == NULL)
432 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700433
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 pXFAMenuHander->Redo((IXFA_Widget*)hWidget);
Bo Xufdc00a72014-10-28 23:03:33 -0700435}
436
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document,
438 FPDF_WIDGET hWidget) {
439 if (NULL == hWidget || NULL == document)
440 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700441
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
443 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
444 pDocument->GetDocType() != XFA_DOCTYPE_Static)
445 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700446
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 IXFA_MenuHandler* pXFAMenuHander =
448 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
449 if (pXFAMenuHander == NULL)
450 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700451
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 pXFAMenuHander->SelectAll((IXFA_Widget*)hWidget);
Bo Xufdc00a72014-10-28 23:03:33 -0700453}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document,
455 FPDF_WIDGET hWidget,
456 FPDF_WIDESTRING wsText,
457 FPDF_DWORD* size) {
458 if (NULL == hWidget || NULL == document)
459 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700460
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
462 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
463 pDocument->GetDocType() != XFA_DOCTYPE_Static)
464 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700465
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 IXFA_MenuHandler* pXFAMenuHander =
467 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
468 if (pXFAMenuHander == NULL)
469 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 CFX_WideString wsCpText;
472 pXFAMenuHander->Copy((IXFA_Widget*)hWidget, wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700473
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
475 int len = bsCpText.GetLength() / sizeof(unsigned short);
476 if (wsText == NULL) {
477 *size = len;
478 return;
479 }
Bo Xufdc00a72014-10-28 23:03:33 -0700480
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 int real_size = len < *size ? len : *size;
482 if (real_size > 0) {
483 FXSYS_memcpy((void*)wsText,
484 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
485 real_size * sizeof(unsigned short));
486 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
487 }
488 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700489}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document,
491 FPDF_WIDGET hWidget,
492 FPDF_WIDESTRING wsText,
493 FPDF_DWORD* size) {
494 if (NULL == hWidget || NULL == document)
495 return;
496 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
497 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
498 pDocument->GetDocType() != XFA_DOCTYPE_Static)
499 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700500
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 IXFA_MenuHandler* pXFAMenuHander =
502 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
503 if (pXFAMenuHander == NULL)
504 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700505
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 CFX_WideString wsCpText;
507 pXFAMenuHander->Cut((IXFA_Widget*)hWidget, wsCpText);
Bo Xufdc00a72014-10-28 23:03:33 -0700508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
510 int len = bsCpText.GetLength() / sizeof(unsigned short);
511 if (wsText == NULL) {
512 *size = len;
513 return;
514 }
Bo Xufdc00a72014-10-28 23:03:33 -0700515
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 int real_size = len < *size ? len : *size;
517 if (real_size > 0) {
518 FXSYS_memcpy((void*)wsText,
519 bsCpText.GetBuffer(real_size * sizeof(unsigned short)),
520 real_size * sizeof(unsigned short));
521 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short));
522 }
523 *size = real_size;
Bo Xufdc00a72014-10-28 23:03:33 -0700524}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document,
526 FPDF_WIDGET hWidget,
527 FPDF_WIDESTRING wsText,
528 FPDF_DWORD size) {
529 if (NULL == hWidget || NULL == document)
530 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700531
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
533 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
534 pDocument->GetDocType() != XFA_DOCTYPE_Static)
535 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700536
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 IXFA_MenuHandler* pXFAMenuHander =
538 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
539 if (pXFAMenuHander == NULL)
540 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700541
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
543 pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr);
Bo Xufdc00a72014-10-28 23:03:33 -0700544}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545DLLEXPORT void STDCALL
546FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document,
547 FPDF_WIDGET hWidget,
548 float x,
549 float y,
550 FPDF_BYTESTRING bsText) {
551 if (NULL == hWidget || NULL == document)
552 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700553
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
555 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
556 pDocument->GetDocType() != XFA_DOCTYPE_Static)
557 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 IXFA_MenuHandler* pXFAMenuHander =
560 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
561 if (pXFAMenuHander == NULL)
562 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700563
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 CFX_PointF ptPopup;
565 ptPopup.x = x;
566 ptPopup.y = y;
567 CFX_ByteStringC bs(bsText);
568 pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs);
Bo Xufdc00a72014-10-28 23:03:33 -0700569}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570DLLEXPORT void STDCALL
571FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document,
572 FPDF_WIDGET hWidget,
573 float x,
574 float y,
575 FPDF_STRINGHANDLE* stringHandle) {
576 if (NULL == hWidget || NULL == document)
577 return;
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700578
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
580 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic &&
581 pDocument->GetDocType() != XFA_DOCTYPE_Static)
582 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700583
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 IXFA_MenuHandler* pXFAMenuHander =
585 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler();
586 if (pXFAMenuHander == NULL)
587 return;
Bo Xufdc00a72014-10-28 23:03:33 -0700588
Tom Sepezae51c812015-08-05 12:34:06 -0700589 CFX_ByteStringArray* sSuggestWords = new CFX_ByteStringArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 CFX_PointF ptPopup;
591 ptPopup.x = x;
592 ptPopup.y = y;
593 pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup,
594 *sSuggestWords);
595 *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords;
Bo Xufdc00a72014-10-28 23:03:33 -0700596}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle) {
598 if (stringHandle == NULL)
599 return -1;
600 CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle;
601 return sSuggestWords->GetSize();
Bo Xufdc00a72014-10-28 23:03:33 -0700602}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603DLLEXPORT FPDF_BOOL STDCALL
604FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle,
605 int index,
606 FPDF_BYTESTRING bsText,
607 FPDF_DWORD* size) {
608 if (stringHandle == NULL || size == NULL)
609 return FALSE;
610 int count = FPDF_StringHandleCounts(stringHandle);
611 if (index < 0 || index >= count)
612 return FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700613
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle;
615 int len = sSuggestWords[index].GetLength();
Bo Xufdc00a72014-10-28 23:03:33 -0700616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 if (bsText == NULL) {
618 *size = len;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700619 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 }
621
622 int real_size = len < *size ? len : *size;
623 if (real_size > 0)
624 FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]),
625 real_size);
626 *size = real_size;
627
628 return TRUE;
Bo Xufdc00a72014-10-28 23:03:33 -0700629}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630DLLEXPORT void STDCALL
631FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) {
632 if (stringHandle == NULL)
633 return;
634 CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle;
635 delete sSuggestWords;
Bo Xufdc00a72014-10-28 23:03:33 -0700636}
637
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638DLLEXPORT FPDF_BOOL STDCALL
639FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle,
640 FPDF_BYTESTRING bsText,
641 FPDF_DWORD size) {
642 if (stringHandle == NULL || bsText == NULL || size <= 0)
643 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700644
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle;
646 CFX_ByteString bsStr(bsText, size);
Bo Xufdc00a72014-10-28 23:03:33 -0700647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 stringArr->Add(bsStr);
649 return TRUE;
Tom Sepez51da0932015-11-25 16:05:49 -0800650#endif
Bo Xufdc00a72014-10-28 23:03:33 -0700651}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
654 int fieldType,
655 unsigned long color) {
656 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
657 pInterForm->SetHighlightColor(color, fieldType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658}
659
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle,
661 unsigned char alpha) {
662 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
663 pInterForm->SetHighlightAlpha(alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664}
665
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
667 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
668 pInterForm->RemoveAllHighLight();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700669}
670
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page,
672 FPDF_FORMHANDLE hHandle) {
673 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page))
674 pPageView->SetValid(TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700675}
676
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page,
678 FPDF_FORMHANDLE hHandle) {
Tom Sepez540c4362015-11-24 13:33:57 -0800679 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700681
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument();
683 if (!pSDKDoc)
684 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700685
Tom Sepez540c4362015-11-24 13:33:57 -0800686 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
687 if (!pPage)
688 return;
689
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
691 if (pPageView) {
692 pPageView->SetValid(FALSE);
Tom Sepez50d12ad2015-11-24 09:50:51 -0800693 // RemovePageView() takes care of the delete for us.
694 pSDKDoc->RemovePageView(pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 }
696}
697
698DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) {
699 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
700 if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
701 pSDKDoc->ProcJavascriptFun();
702}
703
704DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle) {
705 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
706 if (pSDKDoc && ((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
707 pSDKDoc->ProcOpenAction();
708}
709
710DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle,
711 int aaType) {
712 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle);
713 if (!pSDKDoc)
714 return;
715
Tom Sepez50d12ad2015-11-24 09:50:51 -0800716 CPDF_Document* pDoc = pSDKDoc->GetPDFDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 CPDF_Dictionary* pDic = pDoc->GetRoot();
718 if (!pDic)
719 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700720
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 CPDF_AAction aa = pDic->GetDict(FX_BSTRC("AA"));
722 if (aa.ActionExist((CPDF_AAction::AActionType)aaType)) {
723 CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
724 CPDFSDK_ActionHandler* pActionHandler =
725 ((CPDFDoc_Environment*)hHandle)->GetActionHander();
726 ASSERT(pActionHandler != NULL);
727 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType,
728 pSDKDoc);
729 }
730}
731
732DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page,
733 FPDF_FORMHANDLE hHandle,
734 int aaType) {
Tom Sepez540c4362015-11-24 13:33:57 -0800735 if (!hHandle)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 return;
737 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument();
Tom Sepez540c4362015-11-24 13:33:57 -0800738 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page);
739 CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page);
Tom Sepezde4791d2015-10-30 12:13:10 -0700740 if (!pPDFPage)
741 return;
742 if (pSDKDoc->GetPageView(pPage, FALSE)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv();
744 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
Tom Sepezde4791d2015-10-30 12:13:10 -0700745 CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 if (FPDFPAGE_AACTION_OPEN == aaType) {
Tom Sepezde4791d2015-10-30 12:13:10 -0700748 if (aa.ActionExist(CPDF_AAction::OpenPage)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
750 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);
751 }
752 } else {
Tom Sepezde4791d2015-10-30 12:13:10 -0700753 if (aa.ActionExist(CPDF_AAction::ClosePage)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
755 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);
756 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700757 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}