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

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

Issue 2334323005: Rename dictionary set and get methods (Closed)
Patch Set: Created 4 years, 3 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 | « core/fpdfdoc/cpdf_formcontrol.cpp ('k') | core/fpdfdoc/cpdf_formfield_unittest.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/include/cpdf_formfield.h" 7 #include "core/fpdfdoc/include/cpdf_formfield.h"
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } // namespace 49 } // namespace
50 50
51 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, 51 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict,
52 const FX_CHAR* name, 52 const FX_CHAR* name,
53 int nLevel) { 53 int nLevel) {
54 if (nLevel > kMaxRecursion) 54 if (nLevel > kMaxRecursion)
55 return nullptr; 55 return nullptr;
56 if (!pFieldDict) 56 if (!pFieldDict)
57 return nullptr; 57 return nullptr;
58 58
59 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); 59 CPDF_Object* pAttr = pFieldDict->GetDirectObjectFor(name);
60 if (pAttr) 60 if (pAttr)
61 return pAttr; 61 return pAttr;
62 62
63 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); 63 CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent");
64 if (!pParent) 64 if (!pParent)
65 return nullptr; 65 return nullptr;
66 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); 66 return FPDF_GetFieldAttr(pParent, name, nLevel + 1);
67 } 67 }
68 68
69 CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { 69 CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) {
70 CFX_WideString full_name; 70 CFX_WideString full_name;
71 std::set<CPDF_Dictionary*> visited; 71 std::set<CPDF_Dictionary*> visited;
72 CPDF_Dictionary* pLevel = pFieldDict; 72 CPDF_Dictionary* pLevel = pFieldDict;
73 while (pLevel) { 73 while (pLevel) {
74 visited.insert(pLevel); 74 visited.insert(pLevel);
75 CFX_WideString short_name = pLevel->GetUnicodeTextBy("T"); 75 CFX_WideString short_name = pLevel->GetUnicodeTextFor("T");
76 if (!short_name.IsEmpty()) { 76 if (!short_name.IsEmpty()) {
77 if (full_name.IsEmpty()) 77 if (full_name.IsEmpty())
78 full_name = short_name; 78 full_name = short_name;
79 else 79 else
80 full_name = short_name + L"." + full_name; 80 full_name = short_name + L"." + full_name;
81 } 81 }
82 pLevel = pLevel->GetDictBy("Parent"); 82 pLevel = pLevel->GetDictFor("Parent");
83 if (pdfium::ContainsKey(visited, pLevel)) 83 if (pdfium::ContainsKey(visited, pLevel))
84 break; 84 break;
85 } 85 }
86 return full_name; 86 return full_name;
87 } 87 }
88 88
89 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) 89 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict)
90 : m_Type(Unknown), 90 : m_Type(Unknown),
91 m_pForm(pForm), 91 m_pForm(pForm),
92 m_pDict(pDict), 92 m_pDict(pDict),
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return FALSE; 216 return FALSE;
217 217
218 if (bNotify && !NotifyBeforeValueChange(csDValue)) 218 if (bNotify && !NotifyBeforeValueChange(csDValue))
219 return FALSE; 219 return FALSE;
220 220
221 if (pDV) { 221 if (pDV) {
222 CPDF_Object* pClone = pDV->Clone(); 222 CPDF_Object* pClone = pDV->Clone();
223 if (!pClone) 223 if (!pClone)
224 return FALSE; 224 return FALSE;
225 225
226 m_pDict->SetAt("V", pClone); 226 m_pDict->SetFor("V", pClone);
227 if (pRV) { 227 if (pRV) {
228 CPDF_Object* pCloneR = pDV->Clone(); 228 CPDF_Object* pCloneR = pDV->Clone();
229 m_pDict->SetAt("RV", pCloneR); 229 m_pDict->SetFor("RV", pCloneR);
230 } 230 }
231 } else { 231 } else {
232 m_pDict->RemoveAt("V"); 232 m_pDict->RemoveFor("V");
233 m_pDict->RemoveAt("RV"); 233 m_pDict->RemoveFor("RV");
234 } 234 }
235 if (bNotify) 235 if (bNotify)
236 NotifyAfterValueChange(); 236 NotifyAfterValueChange();
237 break; 237 break;
238 } 238 }
239 } 239 }
240 return TRUE; 240 return TRUE;
241 } 241 }
242 242
243 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const { 243 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 case RichText: 357 case RichText:
358 case Text: 358 case Text:
359 case ComboBox: { 359 case ComboBox: {
360 CFX_WideString csValue = value; 360 CFX_WideString csValue = value;
361 if (bNotify && !NotifyBeforeValueChange(csValue)) 361 if (bNotify && !NotifyBeforeValueChange(csValue))
362 return FALSE; 362 return FALSE;
363 363
364 int iIndex = FindOptionValue(csValue); 364 int iIndex = FindOptionValue(csValue);
365 if (iIndex < 0) { 365 if (iIndex < 0) {
366 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); 366 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue);
367 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); 367 m_pDict->SetStringFor(bDefault ? "DV" : "V", bsEncodeText);
368 if (m_Type == RichText && !bDefault) 368 if (m_Type == RichText && !bDefault)
369 m_pDict->SetAtString("RV", bsEncodeText); 369 m_pDict->SetStringFor("RV", bsEncodeText);
370 m_pDict->RemoveAt("I"); 370 m_pDict->RemoveFor("I");
371 } else { 371 } else {
372 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); 372 m_pDict->SetStringFor(bDefault ? "DV" : "V", PDF_EncodeText(csValue));
373 if (!bDefault) { 373 if (!bDefault) {
374 ClearSelection(); 374 ClearSelection();
375 SetItemSelection(iIndex, TRUE); 375 SetItemSelection(iIndex, TRUE);
376 } 376 }
377 } 377 }
378 if (bNotify) 378 if (bNotify)
379 NotifyAfterValueChange(); 379 NotifyAfterValueChange();
380 break; 380 break;
381 } 381 }
382 case ListBox: { 382 case ListBox: {
(...skipping 29 matching lines...) Expand all
412 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) 412 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen"))
413 return pObj->GetInteger(); 413 return pObj->GetInteger();
414 414
415 for (int i = 0; i < m_ControlList.GetSize(); i++) { 415 for (int i = 0; i < m_ControlList.GetSize(); i++) {
416 CPDF_FormControl* pControl = m_ControlList.GetAt(i); 416 CPDF_FormControl* pControl = m_ControlList.GetAt(i);
417 if (!pControl) 417 if (!pControl)
418 continue; 418 continue;
419 419
420 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; 420 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
421 if (pWidgetDict->KeyExist("MaxLen")) 421 if (pWidgetDict->KeyExist("MaxLen"))
422 return pWidgetDict->GetIntegerBy("MaxLen"); 422 return pWidgetDict->GetIntegerFor("MaxLen");
423 } 423 }
424 return 0; 424 return 0;
425 } 425 }
426 426
427 int CPDF_FormField::CountSelectedItems() const { 427 int CPDF_FormField::CountSelectedItems() const {
428 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 428 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
429 if (!pValue) { 429 if (!pValue) {
430 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 430 pValue = FPDF_GetFieldAttr(m_pDict, "I");
431 if (!pValue) 431 if (!pValue)
432 return 0; 432 return 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { 479 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) {
480 if (bNotify && m_pForm->m_pFormNotify) { 480 if (bNotify && m_pForm->m_pFormNotify) {
481 CFX_WideString csValue; 481 CFX_WideString csValue;
482 int iIndex = GetSelectedIndex(0); 482 int iIndex = GetSelectedIndex(0);
483 if (iIndex >= 0) 483 if (iIndex >= 0)
484 csValue = GetOptionLabel(iIndex); 484 csValue = GetOptionLabel(iIndex);
485 485
486 if (!NotifyListOrComboBoxBeforeChange(csValue)) 486 if (!NotifyListOrComboBoxBeforeChange(csValue))
487 return FALSE; 487 return FALSE;
488 } 488 }
489 m_pDict->RemoveAt("V"); 489 m_pDict->RemoveFor("V");
490 m_pDict->RemoveAt("I"); 490 m_pDict->RemoveFor("I");
491 if (bNotify) 491 if (bNotify)
492 NotifyListOrComboBoxAfterChange(); 492 NotifyListOrComboBoxAfterChange();
493 return TRUE; 493 return TRUE;
494 } 494 }
495 495
496 FX_BOOL CPDF_FormField::IsItemSelected(int index) const { 496 FX_BOOL CPDF_FormField::IsItemSelected(int index) const {
497 ASSERT(GetType() == ComboBox || GetType() == ListBox); 497 ASSERT(GetType() == ComboBox || GetType() == ListBox);
498 if (index < 0 || index >= CountOptions()) 498 if (index < 0 || index >= CountOptions())
499 return FALSE; 499 return FALSE;
500 if (IsOptionSelected(index)) 500 if (IsOptionSelected(index))
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 return FALSE; 544 return FALSE;
545 545
546 CFX_WideString opt_value = GetOptionValue(index); 546 CFX_WideString opt_value = GetOptionValue(index);
547 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) 547 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value))
548 return FALSE; 548 return FALSE;
549 549
550 if (bSelected) { 550 if (bSelected) {
551 if (GetType() == ListBox) { 551 if (GetType() == ListBox) {
552 SelectOption(index, TRUE); 552 SelectOption(index, TRUE);
553 if (!(m_Flags & kFormListMultiSelect)) { 553 if (!(m_Flags & kFormListMultiSelect)) {
554 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); 554 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
555 } else { 555 } else {
556 CPDF_Array* pArray = new CPDF_Array; 556 CPDF_Array* pArray = new CPDF_Array;
557 for (int i = 0; i < CountOptions(); i++) { 557 for (int i = 0; i < CountOptions(); i++) {
558 if (i == index || IsItemSelected(i)) { 558 if (i == index || IsItemSelected(i)) {
559 opt_value = GetOptionValue(i); 559 opt_value = GetOptionValue(i);
560 pArray->AddString(PDF_EncodeText(opt_value)); 560 pArray->AddString(PDF_EncodeText(opt_value));
561 } 561 }
562 } 562 }
563 m_pDict->SetAt("V", pArray); 563 m_pDict->SetFor("V", pArray);
564 } 564 }
565 } else { 565 } else {
566 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); 566 m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
567 CPDF_Array* pI = new CPDF_Array; 567 CPDF_Array* pI = new CPDF_Array;
568 pI->AddInteger(index); 568 pI->AddInteger(index);
569 m_pDict->SetAt("I", pI); 569 m_pDict->SetFor("I", pI);
570 } 570 }
571 } else { 571 } else {
572 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 572 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
573 if (pValue) { 573 if (pValue) {
574 if (GetType() == ListBox) { 574 if (GetType() == ListBox) {
575 SelectOption(index, FALSE); 575 SelectOption(index, FALSE);
576 if (pValue->IsString()) { 576 if (pValue->IsString()) {
577 if (pValue->GetUnicodeText() == opt_value) 577 if (pValue->GetUnicodeText() == opt_value)
578 m_pDict->RemoveAt("V"); 578 m_pDict->RemoveFor("V");
579 } else if (pValue->IsArray()) { 579 } else if (pValue->IsArray()) {
580 CPDF_Array* pArray = new CPDF_Array; 580 CPDF_Array* pArray = new CPDF_Array;
581 for (int i = 0; i < CountOptions(); i++) { 581 for (int i = 0; i < CountOptions(); i++) {
582 if (i != index && IsItemSelected(i)) { 582 if (i != index && IsItemSelected(i)) {
583 opt_value = GetOptionValue(i); 583 opt_value = GetOptionValue(i);
584 pArray->AddString(PDF_EncodeText(opt_value)); 584 pArray->AddString(PDF_EncodeText(opt_value));
585 } 585 }
586 } 586 }
587 if (pArray->GetCount() < 1) 587 if (pArray->GetCount() < 1)
588 pArray->Release(); 588 pArray->Release();
589 else 589 else
590 m_pDict->SetAt("V", pArray); 590 m_pDict->SetFor("V", pArray);
591 } 591 }
592 } else { 592 } else {
593 m_pDict->RemoveAt("V"); 593 m_pDict->RemoveFor("V");
594 m_pDict->RemoveAt("I"); 594 m_pDict->RemoveFor("I");
595 } 595 }
596 } 596 }
597 } 597 }
598 if (bNotify) 598 if (bNotify)
599 NotifyListOrComboBoxAfterChange(); 599 NotifyListOrComboBoxAfterChange();
600 return TRUE; 600 return TRUE;
601 } 601 }
602 602
603 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) const { 603 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) const {
604 ASSERT(GetType() == ComboBox || GetType() == ListBox); 604 ASSERT(GetType() == ComboBox || GetType() == ListBox);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 676
677 if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) 677 if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel))
678 return -1; 678 return -1;
679 679
680 CFX_ByteString csStr = 680 CFX_ByteString csStr =
681 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); 681 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength());
682 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 682 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
683 CPDF_Array* pOpt = ToArray(pValue); 683 CPDF_Array* pOpt = ToArray(pValue);
684 if (!pOpt) { 684 if (!pOpt) {
685 pOpt = new CPDF_Array; 685 pOpt = new CPDF_Array;
686 m_pDict->SetAt("Opt", pOpt); 686 m_pDict->SetFor("Opt", pOpt);
687 } 687 }
688 688
689 int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount()); 689 int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount());
690 if (index >= iCount) { 690 if (index >= iCount) {
691 pOpt->AddString(csStr); 691 pOpt->AddString(csStr);
692 index = iCount; 692 index = iCount;
693 } else { 693 } else {
694 CPDF_String* pString = new CPDF_String(csStr, FALSE); 694 CPDF_String* pString = new CPDF_String(csStr, FALSE);
695 pOpt->InsertAt(index, pString); 695 pOpt->InsertAt(index, pString);
696 } 696 }
697 697
698 if (bNotify) 698 if (bNotify)
699 NotifyListOrComboBoxAfterChange(); 699 NotifyListOrComboBoxAfterChange();
700 return index; 700 return index;
701 } 701 }
702 702
703 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { 703 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) {
704 if (bNotify && m_pForm->m_pFormNotify) { 704 if (bNotify && m_pForm->m_pFormNotify) {
705 CFX_WideString csValue; 705 CFX_WideString csValue;
706 int iIndex = GetSelectedIndex(0); 706 int iIndex = GetSelectedIndex(0);
707 if (iIndex >= 0) 707 if (iIndex >= 0)
708 csValue = GetOptionLabel(iIndex); 708 csValue = GetOptionLabel(iIndex);
709 if (!NotifyListOrComboBoxBeforeChange(csValue)) 709 if (!NotifyListOrComboBoxBeforeChange(csValue))
710 return FALSE; 710 return FALSE;
711 } 711 }
712 712
713 m_pDict->RemoveAt("Opt"); 713 m_pDict->RemoveFor("Opt");
714 m_pDict->RemoveAt("V"); 714 m_pDict->RemoveFor("V");
715 m_pDict->RemoveAt("DV"); 715 m_pDict->RemoveFor("DV");
716 m_pDict->RemoveAt("I"); 716 m_pDict->RemoveFor("I");
717 m_pDict->RemoveAt("TI"); 717 m_pDict->RemoveFor("TI");
718 718
719 if (bNotify) 719 if (bNotify)
720 NotifyListOrComboBoxAfterChange(); 720 NotifyListOrComboBoxAfterChange();
721 721
722 return TRUE; 722 return TRUE;
723 } 723 }
724 #endif // PDF_ENABLE_XFA 724 #endif // PDF_ENABLE_XFA
725 725
726 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, 726 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex,
727 bool bChecked, 727 bool bChecked,
(...skipping 25 matching lines...) Expand all
753 if (i == iControlIndex) 753 if (i == iControlIndex)
754 pCtrl->CheckControl(bChecked); 754 pCtrl->CheckControl(bChecked);
755 else if (bChecked) 755 else if (bChecked)
756 pCtrl->CheckControl(FALSE); 756 pCtrl->CheckControl(FALSE);
757 } 757 }
758 } 758 }
759 759
760 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 760 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
761 if (!ToArray(pOpt)) { 761 if (!ToArray(pOpt)) {
762 if (bChecked) { 762 if (bChecked) {
763 m_pDict->SetAtName("V", csBExport); 763 m_pDict->SetNameFor("V", csBExport);
764 } else { 764 } else {
765 CFX_ByteString csV; 765 CFX_ByteString csV;
766 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 766 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
767 if (pV) 767 if (pV)
768 csV = pV->GetString(); 768 csV = pV->GetString();
769 if (csV == csBExport) 769 if (csV == csBExport)
770 m_pDict->SetAtName("V", "Off"); 770 m_pDict->SetNameFor("V", "Off");
771 } 771 }
772 } else if (bChecked) { 772 } else if (bChecked) {
773 CFX_ByteString csIndex; 773 CFX_ByteString csIndex;
774 csIndex.Format("%d", iControlIndex); 774 csIndex.Format("%d", iControlIndex);
775 m_pDict->SetAtName("V", csIndex); 775 m_pDict->SetNameFor("V", csIndex);
776 } 776 }
777 if (bNotify && m_pForm->m_pFormNotify) 777 if (bNotify && m_pForm->m_pFormNotify)
778 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); 778 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this);
779 return TRUE; 779 return TRUE;
780 } 780 }
781 781
782 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) const { 782 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) const {
783 ASSERT(GetType() == CheckBox || GetType() == RadioButton); 783 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
784 CFX_WideString csExport = L"Off"; 784 CFX_WideString csExport = L"Off";
785 int iCount = CountControls(); 785 int iCount = CountControls();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 for (CPDF_Object* pObj : *pArray) { 843 for (CPDF_Object* pObj : *pArray) {
844 if (pObj->GetInteger() == iOptIndex) 844 if (pObj->GetInteger() == iOptIndex)
845 return TRUE; 845 return TRUE;
846 } 846 }
847 return FALSE; 847 return FALSE;
848 } 848 }
849 849
850 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, 850 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex,
851 FX_BOOL bSelected, 851 FX_BOOL bSelected,
852 FX_BOOL bNotify) { 852 FX_BOOL bNotify) {
853 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); 853 CPDF_Array* pArray = m_pDict->GetArrayFor("I");
854 if (!pArray) { 854 if (!pArray) {
855 if (!bSelected) 855 if (!bSelected)
856 return TRUE; 856 return TRUE;
857 857
858 pArray = new CPDF_Array; 858 pArray = new CPDF_Array;
859 m_pDict->SetAt("I", pArray); 859 m_pDict->SetFor("I", pArray);
860 } 860 }
861 861
862 FX_BOOL bReturn = FALSE; 862 FX_BOOL bReturn = FALSE;
863 for (size_t i = 0; i < pArray->GetCount(); i++) { 863 for (size_t i = 0; i < pArray->GetCount(); i++) {
864 int iFind = pArray->GetIntegerAt(i); 864 int iFind = pArray->GetIntegerAt(i);
865 if (iFind == iOptIndex) { 865 if (iFind == iOptIndex) {
866 if (bSelected) 866 if (bSelected)
867 return TRUE; 867 return TRUE;
868 868
869 if (bNotify && m_pForm->m_pFormNotify) { 869 if (bNotify && m_pForm->m_pFormNotify) {
(...skipping 18 matching lines...) Expand all
888 pArray->InsertAt(i, new CPDF_Number(iOptIndex)); 888 pArray->InsertAt(i, new CPDF_Number(iOptIndex));
889 bReturn = TRUE; 889 bReturn = TRUE;
890 break; 890 break;
891 } 891 }
892 } 892 }
893 if (!bReturn) { 893 if (!bReturn) {
894 if (bSelected) 894 if (bSelected)
895 pArray->AddInteger(iOptIndex); 895 pArray->AddInteger(iOptIndex);
896 896
897 if (pArray->IsEmpty()) 897 if (pArray->IsEmpty())
898 m_pDict->RemoveAt("I"); 898 m_pDict->RemoveFor("I");
899 } 899 }
900 if (bNotify) 900 if (bNotify)
901 NotifyListOrComboBoxAfterChange(); 901 NotifyListOrComboBoxAfterChange();
902 902
903 return TRUE; 903 return TRUE;
904 } 904 }
905 905
906 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { 906 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) {
907 if (bNotify && m_pForm->m_pFormNotify) { 907 if (bNotify && m_pForm->m_pFormNotify) {
908 CFX_WideString csValue; 908 CFX_WideString csValue;
909 int iIndex = GetSelectedIndex(0); 909 int iIndex = GetSelectedIndex(0);
910 if (iIndex >= 0) 910 if (iIndex >= 0)
911 csValue = GetOptionLabel(iIndex); 911 csValue = GetOptionLabel(iIndex);
912 912
913 if (!NotifyListOrComboBoxBeforeChange(csValue)) 913 if (!NotifyListOrComboBoxBeforeChange(csValue))
914 return FALSE; 914 return FALSE;
915 } 915 }
916 m_pDict->RemoveAt("I"); 916 m_pDict->RemoveFor("I");
917 if (bNotify) 917 if (bNotify)
918 NotifyListOrComboBoxAfterChange(); 918 NotifyListOrComboBoxAfterChange();
919 919
920 return TRUE; 920 return TRUE;
921 } 921 }
922 922
923 void CPDF_FormField::LoadDA() { 923 void CPDF_FormField::LoadDA() {
924 CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; 924 CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict;
925 if (!pFormDict) 925 if (!pFormDict)
926 return; 926 return;
927 927
928 CFX_ByteString DA; 928 CFX_ByteString DA;
929 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA")) 929 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA"))
930 DA = pObj->GetString(); 930 DA = pObj->GetString();
931 931
932 if (DA.IsEmpty()) 932 if (DA.IsEmpty())
933 DA = pFormDict->GetStringBy("DA"); 933 DA = pFormDict->GetStringFor("DA");
934 934
935 if (DA.IsEmpty()) 935 if (DA.IsEmpty())
936 return; 936 return;
937 937
938 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); 938 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
939 if (!pDR) 939 if (!pDR)
940 return; 940 return;
941 941
942 CPDF_Dictionary* pFont = pDR->GetDictBy("Font"); 942 CPDF_Dictionary* pFont = pDR->GetDictFor("Font");
943 if (!pFont) 943 if (!pFont)
944 return; 944 return;
945 945
946 CPDF_SimpleParser syntax(DA.AsStringC()); 946 CPDF_SimpleParser syntax(DA.AsStringC());
947 syntax.FindTagParamFromStart("Tf", 2); 947 syntax.FindTagParamFromStart("Tf", 2);
948 CFX_ByteString font_name(syntax.GetWord()); 948 CFX_ByteString font_name(syntax.GetWord());
949 CPDF_Dictionary* pFontDict = pFont->GetDictBy(font_name); 949 CPDF_Dictionary* pFontDict = pFont->GetDictFor(font_name);
950 if (!pFontDict) 950 if (!pFontDict)
951 return; 951 return;
952 952
953 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 953 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
954 m_FontSize = FX_atof(syntax.GetWord()); 954 m_FontSize = FX_atof(syntax.GetWord());
955 } 955 }
956 956
957 bool CPDF_FormField::NotifyBeforeSelectionChange(const CFX_WideString& value) { 957 bool CPDF_FormField::NotifyBeforeSelectionChange(const CFX_WideString& value) {
958 if (!m_pForm->m_pFormNotify) 958 if (!m_pForm->m_pFormNotify)
959 return true; 959 return true;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 case ListBox: 995 case ListBox:
996 NotifyAfterSelectionChange(); 996 NotifyAfterSelectionChange();
997 break; 997 break;
998 case ComboBox: 998 case ComboBox:
999 NotifyAfterValueChange(); 999 NotifyAfterValueChange();
1000 break; 1000 break;
1001 default: 1001 default:
1002 break; 1002 break;
1003 } 1003 }
1004 } 1004 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_formcontrol.cpp ('k') | core/fpdfdoc/cpdf_formfield_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698