OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "public/fpdf_formfill.h" | 7 #include "public/fpdf_formfill.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> |
10 | 11 |
11 #include "fpdfsdk/include/fsdk_define.h" | 12 #include "fpdfsdk/include/fsdk_define.h" |
12 #include "fpdfsdk/include/fsdk_mgr.h" | 13 #include "fpdfsdk/include/fsdk_mgr.h" |
13 #include "public/fpdfview.h" | 14 #include "public/fpdfview.h" |
| 15 #include "third_party/base/stl_util.h" |
14 | 16 |
15 #ifdef PDF_ENABLE_XFA | 17 #ifdef PDF_ENABLE_XFA |
16 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" | 18 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" |
17 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" | 19 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
18 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" | 20 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h" |
19 #endif // PDF_ENABLE_XFA | 21 #endif // PDF_ENABLE_XFA |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | 25 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
24 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 26 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
25 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; | 27 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; |
26 } | 28 } |
27 | 29 |
28 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 30 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
29 FPDF_PAGE page) { | 31 FPDF_PAGE page) { |
30 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 32 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
31 if (!pPage) | 33 if (!pPage) |
32 return nullptr; | 34 return nullptr; |
33 | 35 |
34 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); | 36 CPDFSDK_Document* pSDKDoc = CPDFSDK_Document::FromFPDFFormHandle(hHandle); |
35 return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr; | 37 return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr; |
36 } | 38 } |
37 | 39 |
| 40 #ifdef PDF_ENABLE_XFA |
| 41 std::vector<CFX_ByteString>* FromFPDFStringHandle(FPDF_STRINGHANDLE handle) { |
| 42 return reinterpret_cast<std::vector<CFX_ByteString>*>(handle); |
| 43 } |
| 44 |
| 45 FPDF_STRINGHANDLE ToFPDFStringHandle(std::vector<CFX_ByteString>* strings) { |
| 46 return reinterpret_cast<FPDF_STRINGHANDLE>(strings); |
| 47 } |
| 48 #endif // PDF_ENABLE_XFA |
| 49 |
38 } // namespace | 50 } // namespace |
39 | 51 |
40 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, | 52 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
41 FPDF_PAGE page, | 53 FPDF_PAGE page, |
42 double page_x, | 54 double page_x, |
43 double page_y) { | 55 double page_y) { |
44 if (!hHandle) | 56 if (!hHandle) |
45 return -1; | 57 return -1; |
46 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 58 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
47 #ifdef PDF_ENABLE_XFA | 59 #ifdef PDF_ENABLE_XFA |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 472 |
461 int real_size = len < *size ? len : *size; | 473 int real_size = len < *size ? len : *size; |
462 if (real_size > 0) { | 474 if (real_size > 0) { |
463 FXSYS_memcpy((void*)wsText, | 475 FXSYS_memcpy((void*)wsText, |
464 bsCpText.GetBuffer(real_size * sizeof(unsigned short)), | 476 bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
465 real_size * sizeof(unsigned short)); | 477 real_size * sizeof(unsigned short)); |
466 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); | 478 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
467 } | 479 } |
468 *size = real_size; | 480 *size = real_size; |
469 } | 481 } |
| 482 |
470 DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, | 483 DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, |
471 FPDF_WIDGET hWidget, | 484 FPDF_WIDGET hWidget, |
472 FPDF_WIDESTRING wsText, | 485 FPDF_WIDESTRING wsText, |
473 FPDF_DWORD* size) { | 486 FPDF_DWORD* size) { |
474 if (NULL == hWidget || NULL == document) | 487 if (NULL == hWidget || NULL == document) |
475 return; | 488 return; |
476 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; | 489 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
477 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && | 490 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
478 pDocument->GetDocType() != XFA_DOCTYPE_Static) | 491 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
479 return; | 492 return; |
(...skipping 15 matching lines...) Expand all Loading... |
495 | 508 |
496 int real_size = len < *size ? len : *size; | 509 int real_size = len < *size ? len : *size; |
497 if (real_size > 0) { | 510 if (real_size > 0) { |
498 FXSYS_memcpy((void*)wsText, | 511 FXSYS_memcpy((void*)wsText, |
499 bsCpText.GetBuffer(real_size * sizeof(unsigned short)), | 512 bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
500 real_size * sizeof(unsigned short)); | 513 real_size * sizeof(unsigned short)); |
501 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); | 514 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
502 } | 515 } |
503 *size = real_size; | 516 *size = real_size; |
504 } | 517 } |
| 518 |
505 DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, | 519 DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, |
506 FPDF_WIDGET hWidget, | 520 FPDF_WIDGET hWidget, |
507 FPDF_WIDESTRING wsText, | 521 FPDF_WIDESTRING wsText, |
508 FPDF_DWORD size) { | 522 FPDF_DWORD size) { |
509 if (NULL == hWidget || NULL == document) | 523 if (NULL == hWidget || NULL == document) |
510 return; | 524 return; |
511 | 525 |
512 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; | 526 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
513 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && | 527 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
514 pDocument->GetDocType() != XFA_DOCTYPE_Static) | 528 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
515 return; | 529 return; |
516 | 530 |
517 IXFA_MenuHandler* pXFAMenuHander = | 531 IXFA_MenuHandler* pXFAMenuHander = |
518 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); | 532 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
519 if (pXFAMenuHander == NULL) | 533 if (pXFAMenuHander == NULL) |
520 return; | 534 return; |
521 | 535 |
522 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); | 536 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); |
523 pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); | 537 pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); |
524 } | 538 } |
| 539 |
525 DLLEXPORT void STDCALL | 540 DLLEXPORT void STDCALL |
526 FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, | 541 FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, |
527 FPDF_WIDGET hWidget, | 542 FPDF_WIDGET hWidget, |
528 float x, | 543 float x, |
529 float y, | 544 float y, |
530 FPDF_BYTESTRING bsText) { | 545 FPDF_BYTESTRING bsText) { |
531 if (NULL == hWidget || NULL == document) | 546 if (NULL == hWidget || NULL == document) |
532 return; | 547 return; |
533 | 548 |
534 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; | 549 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
535 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && | 550 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
536 pDocument->GetDocType() != XFA_DOCTYPE_Static) | 551 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
537 return; | 552 return; |
538 | 553 |
539 IXFA_MenuHandler* pXFAMenuHander = | 554 IXFA_MenuHandler* pXFAMenuHander = |
540 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); | 555 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
541 if (pXFAMenuHander == NULL) | 556 if (pXFAMenuHander == NULL) |
542 return; | 557 return; |
543 | 558 |
544 CFX_PointF ptPopup; | 559 CFX_PointF ptPopup; |
545 ptPopup.x = x; | 560 ptPopup.x = x; |
546 ptPopup.y = y; | 561 ptPopup.y = y; |
547 CFX_ByteStringC bs(bsText); | 562 CFX_ByteStringC bs(bsText); |
548 pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs); | 563 pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs); |
549 } | 564 } |
| 565 |
550 DLLEXPORT void STDCALL | 566 DLLEXPORT void STDCALL |
551 FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, | 567 FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, |
552 FPDF_WIDGET hWidget, | 568 FPDF_WIDGET hWidget, |
553 float x, | 569 float x, |
554 float y, | 570 float y, |
555 FPDF_STRINGHANDLE* stringHandle) { | 571 FPDF_STRINGHANDLE* stringHandle) { |
556 if (NULL == hWidget || NULL == document) | 572 if (!hWidget || !document) |
557 return; | 573 return; |
558 | 574 |
559 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; | 575 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
560 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && | 576 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
561 pDocument->GetDocType() != XFA_DOCTYPE_Static) | 577 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
562 return; | 578 return; |
563 | 579 |
564 IXFA_MenuHandler* pXFAMenuHander = | 580 IXFA_MenuHandler* pXFAMenuHander = |
565 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); | 581 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
566 if (pXFAMenuHander == NULL) | 582 if (!pXFAMenuHander) |
567 return; | 583 return; |
568 | 584 |
569 CFX_ByteStringArray* sSuggestWords = new CFX_ByteStringArray; | 585 std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>; |
570 CFX_PointF ptPopup; | 586 CFX_PointF ptPopup; |
571 ptPopup.x = x; | 587 ptPopup.x = x; |
572 ptPopup.y = y; | 588 ptPopup.y = y; |
573 pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup, | 589 pXFAMenuHander->GetSuggestWords(reinterpret_cast<IXFA_Widget*>(hWidget), |
574 *sSuggestWords); | 590 ptPopup, *sSuggestWords); |
575 *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; | 591 *stringHandle = ToFPDFStringHandle(sSuggestWords); |
576 } | 592 } |
577 DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle) { | 593 |
578 if (stringHandle == NULL) | 594 DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE sHandle) { |
579 return -1; | 595 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle); |
580 CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; | 596 return sSuggestWords ? pdfium::CollectionSize<int>(*sSuggestWords) : -1; |
581 return sSuggestWords->GetSize(); | |
582 } | 597 } |
| 598 |
583 DLLEXPORT FPDF_BOOL STDCALL | 599 DLLEXPORT FPDF_BOOL STDCALL |
584 FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle, | 600 FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE sHandle, |
585 int index, | 601 int index, |
586 FPDF_BYTESTRING bsText, | 602 FPDF_BYTESTRING bsText, |
587 FPDF_DWORD* size) { | 603 FPDF_DWORD* size) { |
588 if (stringHandle == NULL || size == NULL) | 604 if (!sHandle || !size) |
589 return FALSE; | 605 return FALSE; |
590 int count = FPDF_StringHandleCounts(stringHandle); | 606 |
| 607 int count = FPDF_StringHandleCounts(sHandle); |
591 if (index < 0 || index >= count) | 608 if (index < 0 || index >= count) |
592 return FALSE; | 609 return FALSE; |
593 | 610 |
594 CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle; | 611 std::vector<CFX_ByteString>* sSuggestWords = FromFPDFStringHandle(sHandle); |
595 int len = sSuggestWords[index].GetLength(); | 612 int len = (*sSuggestWords)[index].GetLength(); |
596 | 613 if (!bsText) { |
597 if (bsText == NULL) { | |
598 *size = len; | 614 *size = len; |
599 return TRUE; | 615 return TRUE; |
600 } | 616 } |
601 | 617 |
602 int real_size = len < *size ? len : *size; | 618 int real_size = len < *size ? len : *size; |
603 if (real_size > 0) | 619 if (real_size > 0) |
604 FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]), | 620 FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(*sSuggestWords)[index], |
605 real_size); | 621 real_size); |
606 *size = real_size; | 622 *size = real_size; |
607 | |
608 return TRUE; | 623 return TRUE; |
609 } | 624 } |
| 625 |
610 DLLEXPORT void STDCALL | 626 DLLEXPORT void STDCALL |
611 FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { | 627 FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { |
612 if (stringHandle == NULL) | 628 delete FromFPDFStringHandle(stringHandle); |
613 return; | |
614 CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; | |
615 delete sSuggestWords; | |
616 } | 629 } |
617 | 630 |
618 DLLEXPORT FPDF_BOOL STDCALL | 631 DLLEXPORT FPDF_BOOL STDCALL |
619 FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, | 632 FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, |
620 FPDF_BYTESTRING bsText, | 633 FPDF_BYTESTRING bsText, |
621 FPDF_DWORD size) { | 634 FPDF_DWORD size) { |
622 if (stringHandle == NULL || bsText == NULL || size <= 0) | 635 if (!stringHandle || !bsText || size == 0) |
623 return FALSE; | 636 return FALSE; |
624 | 637 |
625 CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle; | 638 FromFPDFStringHandle(stringHandle)->push_back(CFX_ByteString(bsText, size)); |
626 CFX_ByteString bsStr(bsText, size); | |
627 | |
628 stringArr->Add(bsStr); | |
629 return TRUE; | 639 return TRUE; |
630 } | 640 } |
631 #endif // PDF_ENABLE_XFA | 641 #endif // PDF_ENABLE_XFA |
632 | 642 |
633 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, | 643 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
634 int fieldType, | 644 int fieldType, |
635 unsigned long color) { | 645 unsigned long color) { |
636 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) | 646 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
637 pInterForm->SetHighlightColor(color, fieldType); | 647 pInterForm->SetHighlightColor(color, fieldType); |
638 } | 648 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 739 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
730 } | 740 } |
731 } else { | 741 } else { |
732 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 742 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
733 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 743 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
734 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 744 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
735 } | 745 } |
736 } | 746 } |
737 } | 747 } |
738 } | 748 } |
OLD | NEW |