Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: fpdfsdk/src/fpdfformfill.cpp

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

Powered by Google App Engine
This is Rietveld 408576698