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

Side by Side Diff: core/fpdfdoc/cpdf_formfield.cpp

Issue 2498223005: Make CPDF_Array take unique_ptrs (Closed)
Patch Set: nits Created 4 years, 1 month 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 | « core/fpdfdoc/cpdf_dest_unittest.cpp ('k') | core/fpdfdoc/cpdf_interform.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/fpdfdoc/cpdf_formfield.h" 7 #include "core/fpdfdoc/cpdf_formfield.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (bSelected) { 548 if (bSelected) {
549 if (GetType() == ListBox) { 549 if (GetType() == ListBox) {
550 SelectOption(index, true); 550 SelectOption(index, true);
551 if (!(m_Flags & kFormListMultiSelect)) { 551 if (!(m_Flags & kFormListMultiSelect)) {
552 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); 552 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
553 } else { 553 } else {
554 CPDF_Array* pArray = new CPDF_Array; 554 CPDF_Array* pArray = new CPDF_Array;
555 for (int i = 0; i < CountOptions(); i++) { 555 for (int i = 0; i < CountOptions(); i++) {
556 if (i == index || IsItemSelected(i)) { 556 if (i == index || IsItemSelected(i)) {
557 opt_value = GetOptionValue(i); 557 opt_value = GetOptionValue(i);
558 pArray->AddString(PDF_EncodeText(opt_value)); 558 pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false);
559 } 559 }
560 } 560 }
561 m_pDict->SetFor("V", pArray); 561 m_pDict->SetFor("V", pArray);
562 } 562 }
563 } else { 563 } else {
564 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); 564 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
565 CPDF_Array* pI = new CPDF_Array; 565 CPDF_Array* pI = new CPDF_Array;
566 pI->AddInteger(index); 566 pI->AddNew<CPDF_Number>(index);
567 m_pDict->SetFor("I", pI); 567 m_pDict->SetFor("I", pI);
568 } 568 }
569 } else { 569 } else {
570 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 570 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
571 if (pValue) { 571 if (pValue) {
572 if (GetType() == ListBox) { 572 if (GetType() == ListBox) {
573 SelectOption(index, false); 573 SelectOption(index, false);
574 if (pValue->IsString()) { 574 if (pValue->IsString()) {
575 if (pValue->GetUnicodeText() == opt_value) 575 if (pValue->GetUnicodeText() == opt_value)
576 m_pDict->RemoveFor("V"); 576 m_pDict->RemoveFor("V");
577 } else if (pValue->IsArray()) { 577 } else if (pValue->IsArray()) {
578 std::unique_ptr<CPDF_Array> pArray(new CPDF_Array); 578 std::unique_ptr<CPDF_Array> pArray(new CPDF_Array);
579 for (int i = 0; i < CountOptions(); i++) { 579 for (int i = 0; i < CountOptions(); i++) {
580 if (i != index && IsItemSelected(i)) { 580 if (i != index && IsItemSelected(i)) {
581 opt_value = GetOptionValue(i); 581 opt_value = GetOptionValue(i);
582 pArray->AddString(PDF_EncodeText(opt_value)); 582 pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false);
583 } 583 }
584 } 584 }
585 if (pArray->GetCount() > 0) 585 if (pArray->GetCount() > 0)
586 m_pDict->SetFor("V", pArray.release()); // std::move someday 586 m_pDict->SetFor("V", pArray.release()); // std::move someday
587 } 587 }
588 } else { 588 } else {
589 m_pDict->RemoveFor("V"); 589 m_pDict->RemoveFor("V");
590 m_pDict->RemoveFor("I"); 590 m_pDict->RemoveFor("I");
591 } 591 }
592 } 592 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); 677 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength());
678 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 678 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
679 CPDF_Array* pOpt = ToArray(pValue); 679 CPDF_Array* pOpt = ToArray(pValue);
680 if (!pOpt) { 680 if (!pOpt) {
681 pOpt = new CPDF_Array; 681 pOpt = new CPDF_Array;
682 m_pDict->SetFor("Opt", pOpt); 682 m_pDict->SetFor("Opt", pOpt);
683 } 683 }
684 684
685 int iCount = pdfium::base::checked_cast<int>(pOpt->GetCount()); 685 int iCount = pdfium::base::checked_cast<int>(pOpt->GetCount());
686 if (index >= iCount) { 686 if (index >= iCount) {
687 pOpt->AddString(csStr); 687 pOpt->AddNew<CPDF_String>(csStr, false);
688 index = iCount; 688 index = iCount;
689 } else { 689 } else {
690 CPDF_String* pString = new CPDF_String(csStr, false); 690 pOpt->InsertNewAt<CPDF_String>(index, csStr, false);
691 pOpt->InsertAt(index, pString);
692 } 691 }
693 692
694 if (bNotify) 693 if (bNotify)
695 NotifyListOrComboBoxAfterChange(); 694 NotifyListOrComboBoxAfterChange();
696 return index; 695 return index;
697 } 696 }
698 697
699 bool CPDF_FormField::ClearOptions(bool bNotify) { 698 bool CPDF_FormField::ClearOptions(bool bNotify) {
700 if (bNotify && m_pForm->m_pFormNotify) { 699 if (bNotify && m_pForm->m_pFormNotify) {
701 CFX_WideString csValue; 700 CFX_WideString csValue;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 if (iCount < 0 || index >= iCount) 828 if (iCount < 0 || index >= iCount)
830 return -1; 829 return -1;
831 return pArray->GetIntegerAt(index); 830 return pArray->GetIntegerAt(index);
832 } 831 }
833 832
834 bool CPDF_FormField::IsOptionSelected(int iOptIndex) const { 833 bool CPDF_FormField::IsOptionSelected(int iOptIndex) const {
835 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); 834 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I"));
836 if (!pArray) 835 if (!pArray)
837 return false; 836 return false;
838 837
839 for (CPDF_Object* pObj : *pArray) { 838 for (const auto& pObj : *pArray) {
840 if (pObj->GetInteger() == iOptIndex) 839 if (pObj->GetInteger() == iOptIndex)
841 return true; 840 return true;
842 } 841 }
843 return false; 842 return false;
844 } 843 }
845 844
846 bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) { 845 bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
847 CPDF_Array* pArray = m_pDict->GetArrayFor("I"); 846 CPDF_Array* pArray = m_pDict->GetArrayFor("I");
848 if (!pArray) { 847 if (!pArray) {
849 if (!bSelected) 848 if (!bSelected)
(...skipping 22 matching lines...) Expand all
872 871
873 if (iFind > iOptIndex) { 872 if (iFind > iOptIndex) {
874 if (!bSelected) 873 if (!bSelected)
875 continue; 874 continue;
876 875
877 if (bNotify && m_pForm->m_pFormNotify) { 876 if (bNotify && m_pForm->m_pFormNotify) {
878 CFX_WideString csValue = GetOptionLabel(iOptIndex); 877 CFX_WideString csValue = GetOptionLabel(iOptIndex);
879 if (!NotifyListOrComboBoxBeforeChange(csValue)) 878 if (!NotifyListOrComboBoxBeforeChange(csValue))
880 return false; 879 return false;
881 } 880 }
882 pArray->InsertAt(i, new CPDF_Number(iOptIndex)); 881 pArray->InsertNewAt<CPDF_Number>(i, iOptIndex);
883 bReturn = true; 882 bReturn = true;
884 break; 883 break;
885 } 884 }
886 } 885 }
887 if (!bReturn) { 886 if (!bReturn) {
888 if (bSelected) 887 if (bSelected)
889 pArray->AddInteger(iOptIndex); 888 pArray->AddNew<CPDF_Number>(iOptIndex);
890 889
891 if (pArray->IsEmpty()) 890 if (pArray->IsEmpty())
892 m_pDict->RemoveFor("I"); 891 m_pDict->RemoveFor("I");
893 } 892 }
894 if (bNotify) 893 if (bNotify)
895 NotifyListOrComboBoxAfterChange(); 894 NotifyListOrComboBoxAfterChange();
896 895
897 return true; 896 return true;
898 } 897 }
899 898
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 case ListBox: 988 case ListBox:
990 NotifyAfterSelectionChange(); 989 NotifyAfterSelectionChange();
991 break; 990 break;
992 case ComboBox: 991 case ComboBox:
993 NotifyAfterValueChange(); 992 NotifyAfterValueChange();
994 break; 993 break;
995 default: 994 default:
996 break; 995 break;
997 } 996 }
998 } 997 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_dest_unittest.cpp ('k') | core/fpdfdoc/cpdf_interform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698