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 "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 #include "doc_utils.h" | 8 #include "doc_utils.h" |
9 | 9 |
10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { | 10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 } | 732 } |
733 int iCount = CountOptions(); | 733 int iCount = CountOptions(); |
734 for (; iStartIndex < iCount; iStartIndex++) { | 734 for (; iStartIndex < iCount; iStartIndex++) { |
735 CFX_WideString csValue = GetOptionValue(iStartIndex); | 735 CFX_WideString csValue = GetOptionValue(iStartIndex); |
736 if (csValue == csOptValue) { | 736 if (csValue == csOptValue) { |
737 return iStartIndex; | 737 return iStartIndex; |
738 } | 738 } |
739 } | 739 } |
740 return -1; | 740 return -1; |
741 } | 741 } |
| 742 #ifdef PDF_ENABLE_XFA |
| 743 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, |
| 744 int index, |
| 745 FX_BOOL bNotify) { |
| 746 if (csOptLabel.IsEmpty()) |
| 747 return -1; |
| 748 |
| 749 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 750 int iRet = 0; |
| 751 if (GetType() == ListBox) |
| 752 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel); |
| 753 if (GetType() == ComboBox) |
| 754 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csOptLabel); |
| 755 if (iRet < 0) |
| 756 return -1; |
| 757 } |
| 758 |
| 759 CFX_ByteString csStr = PDF_EncodeText(csOptLabel, csOptLabel.GetLength()); |
| 760 CPDF_Array* pOpt = NULL; |
| 761 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); |
| 762 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { |
| 763 pOpt = CPDF_Array::Create(); |
| 764 if (pOpt == NULL) |
| 765 return -1; |
| 766 m_pDict->SetAt("Opt", pOpt); |
| 767 } else |
| 768 pOpt = (CPDF_Array*)pValue; |
| 769 int iCount = (int)pOpt->GetCount(); |
| 770 if (index < 0 || index >= iCount) { |
| 771 pOpt->AddString(csStr); |
| 772 index = iCount; |
| 773 } else { |
| 774 CPDF_String* pString = CPDF_String::Create(csStr); |
| 775 if (pString == NULL) |
| 776 return -1; |
| 777 pOpt->InsertAt(index, pString); |
| 778 } |
| 779 |
| 780 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 781 if (GetType() == ListBox) |
| 782 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 783 if (GetType() == ComboBox) |
| 784 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 785 } |
| 786 m_pForm->m_bUpdated = TRUE; |
| 787 return index; |
| 788 } |
| 789 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { |
| 790 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 791 int iRet = 0; |
| 792 CFX_WideString csValue; |
| 793 int iIndex = GetSelectedIndex(0); |
| 794 if (iIndex >= 0) |
| 795 csValue = GetOptionLabel(iIndex); |
| 796 if (GetType() == ListBox) |
| 797 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); |
| 798 if (GetType() == ComboBox) |
| 799 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); |
| 800 if (iRet < 0) |
| 801 return FALSE; |
| 802 } |
| 803 |
| 804 m_pDict->RemoveAt("Opt"); |
| 805 m_pDict->RemoveAt("V"); |
| 806 m_pDict->RemoveAt("DV"); |
| 807 m_pDict->RemoveAt("I"); |
| 808 m_pDict->RemoveAt("TI"); |
| 809 |
| 810 if (bNotify && m_pForm->m_pFormNotify != NULL) { |
| 811 if (GetType() == ListBox) |
| 812 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 813 if (GetType() == ComboBox) |
| 814 m_pForm->m_pFormNotify->AfterValueChange(this); |
| 815 } |
| 816 |
| 817 m_pForm->m_bUpdated = TRUE; |
| 818 return TRUE; |
| 819 } |
| 820 #endif |
742 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, | 821 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, |
743 FX_BOOL bChecked, | 822 FX_BOOL bChecked, |
744 FX_BOOL bNotify) { | 823 FX_BOOL bNotify) { |
745 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 824 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
746 CPDF_FormControl* pControl = GetControl(iControlIndex); | 825 CPDF_FormControl* pControl = GetControl(iControlIndex); |
747 if (pControl == NULL) { | 826 if (pControl == NULL) { |
748 return FALSE; | 827 return FALSE; |
749 } | 828 } |
750 if (!bChecked && pControl->IsChecked() == bChecked) { | 829 if (!bChecked && pControl->IsChecked() == bChecked) { |
751 return FALSE; | 830 return FALSE; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) | 1114 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) |
1036 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( | 1115 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( |
1037 font_name); | 1116 font_name); |
1038 | 1117 |
1039 if (pFontDict == NULL) { | 1118 if (pFontDict == NULL) { |
1040 return; | 1119 return; |
1041 } | 1120 } |
1042 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 1121 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
1043 m_FontSize = FX_atof(syntax.GetWord()); | 1122 m_FontSize = FX_atof(syntax.GetWord()); |
1044 } | 1123 } |
OLD | NEW |