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 "core/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 m_Type = Sign; | 95 m_Type = Sign; |
96 } | 96 } |
97 } | 97 } |
98 CFX_WideString CPDF_FormField::GetFullName() { | 98 CFX_WideString CPDF_FormField::GetFullName() { |
99 return ::GetFullName(m_pDict); | 99 return ::GetFullName(m_pDict); |
100 } | 100 } |
101 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { | 101 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { |
102 switch (m_Type) { | 102 switch (m_Type) { |
103 case CPDF_FormField::CheckBox: | 103 case CPDF_FormField::CheckBox: |
104 case CPDF_FormField::RadioButton: { | 104 case CPDF_FormField::RadioButton: { |
105 CFX_ByteArray statusArray; | |
106 if (bNotify && m_pForm->m_pFormNotify) { | |
107 SaveCheckedFieldStatus(this, statusArray); | |
108 } | |
109 int iCount = CountControls(); | 105 int iCount = CountControls(); |
110 if (iCount) { | 106 if (iCount) { |
111 if (PDF_FormField_IsUnison(this)) { | 107 if (PDF_FormField_IsUnison(this)) { |
112 for (int i = 0; i < iCount; i++) { | 108 for (int i = 0; i < iCount; i++) { |
113 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 109 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
114 } | 110 } |
115 } else { | 111 } else { |
116 for (int i = 0; i < iCount; i++) { | 112 for (int i = 0; i < iCount; i++) { |
117 CPDF_FormControl* pControl = GetControl(i); | 113 CPDF_FormControl* pControl = GetControl(i); |
118 FX_BOOL bChecked = pControl->IsDefaultChecked(); | 114 FX_BOOL bChecked = pControl->IsDefaultChecked(); |
119 CheckControl(i, bChecked, FALSE); | 115 CheckControl(i, bChecked, FALSE); |
120 } | 116 } |
121 } | 117 } |
122 } | 118 } |
123 if (bNotify && m_pForm->m_pFormNotify) { | 119 if (bNotify && m_pForm->m_pFormNotify) { |
124 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); | 120 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
125 } | 121 } |
126 } break; | 122 } break; |
127 case CPDF_FormField::ComboBox: { | 123 case CPDF_FormField::ComboBox: { |
128 CFX_WideString csValue; | 124 CFX_WideString csValue; |
129 ClearSelection(); | 125 ClearSelection(); |
130 int iIndex = GetDefaultSelectedItem(); | 126 int iIndex = GetDefaultSelectedItem(); |
131 if (iIndex >= 0) { | 127 if (iIndex >= 0) { |
132 csValue = GetOptionLabel(iIndex); | 128 csValue = GetOptionLabel(iIndex); |
133 } | 129 } |
134 if (bNotify && m_pForm->m_pFormNotify) { | 130 if (bNotify && m_pForm->m_pFormNotify) { |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 794 m_pForm->m_pFormNotify->AfterSelectionChange(this); |
799 if (GetType() == ComboBox) | 795 if (GetType() == ComboBox) |
800 m_pForm->m_pFormNotify->AfterValueChange(this); | 796 m_pForm->m_pFormNotify->AfterValueChange(this); |
801 } | 797 } |
802 | 798 |
803 m_pForm->m_bUpdated = TRUE; | 799 m_pForm->m_bUpdated = TRUE; |
804 return TRUE; | 800 return TRUE; |
805 } | 801 } |
806 #endif // PDF_ENABLE_XFA | 802 #endif // PDF_ENABLE_XFA |
807 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, | 803 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, |
808 FX_BOOL bChecked, | 804 bool bChecked, |
809 FX_BOOL bNotify) { | 805 bool bNotify) { |
810 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 806 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
811 CPDF_FormControl* pControl = GetControl(iControlIndex); | 807 CPDF_FormControl* pControl = GetControl(iControlIndex); |
812 if (!pControl) { | 808 if (!pControl) { |
813 return FALSE; | 809 return FALSE; |
814 } | 810 } |
815 if (!bChecked && pControl->IsChecked() == bChecked) { | 811 if (!bChecked && pControl->IsChecked() == bChecked) { |
816 return FALSE; | 812 return FALSE; |
817 } | 813 } |
818 CFX_ByteArray statusArray; | |
819 if (bNotify && m_pForm->m_pFormNotify) { | |
820 SaveCheckedFieldStatus(this, statusArray); | |
821 } | |
822 CFX_WideString csWExport = pControl->GetExportValue(); | 814 CFX_WideString csWExport = pControl->GetExportValue(); |
823 CFX_ByteString csBExport = PDF_EncodeText(csWExport); | 815 CFX_ByteString csBExport = PDF_EncodeText(csWExport); |
824 int iCount = CountControls(); | 816 int iCount = CountControls(); |
825 FX_BOOL bUnison = PDF_FormField_IsUnison(this); | 817 FX_BOOL bUnison = PDF_FormField_IsUnison(this); |
826 for (int i = 0; i < iCount; i++) { | 818 for (int i = 0; i < iCount; i++) { |
827 CPDF_FormControl* pCtrl = GetControl(i); | 819 CPDF_FormControl* pCtrl = GetControl(i); |
828 if (bUnison) { | 820 if (bUnison) { |
829 CFX_WideString csEValue = pCtrl->GetExportValue(); | 821 CFX_WideString csEValue = pCtrl->GetExportValue(); |
830 if (csEValue == csWExport) { | 822 if (csEValue == csWExport) { |
831 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { | 823 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { |
(...skipping 25 matching lines...) Expand all Loading... |
857 if (csV == csBExport) { | 849 if (csV == csBExport) { |
858 m_pDict->SetAtName("V", "Off"); | 850 m_pDict->SetAtName("V", "Off"); |
859 } | 851 } |
860 } | 852 } |
861 } else if (bChecked) { | 853 } else if (bChecked) { |
862 CFX_ByteString csIndex; | 854 CFX_ByteString csIndex; |
863 csIndex.Format("%d", iControlIndex); | 855 csIndex.Format("%d", iControlIndex); |
864 m_pDict->SetAtName("V", csIndex); | 856 m_pDict->SetAtName("V", csIndex); |
865 } | 857 } |
866 if (bNotify && m_pForm->m_pFormNotify) { | 858 if (bNotify && m_pForm->m_pFormNotify) { |
867 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); | 859 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
868 } | 860 } |
869 m_pForm->m_bUpdated = TRUE; | 861 m_pForm->m_bUpdated = TRUE; |
870 return TRUE; | 862 return TRUE; |
871 } | 863 } |
872 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { | 864 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { |
873 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 865 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
874 CFX_WideString csExport = L"Off"; | 866 CFX_WideString csExport = L"Off"; |
875 FX_BOOL bChecked; | 867 FX_BOOL bChecked; |
876 int iCount = CountControls(); | 868 int iCount = CountControls(); |
877 for (int i = 0; i < iCount; i++) { | 869 for (int i = 0; i < iCount; i++) { |
878 CPDF_FormControl* pControl = GetControl(i); | 870 CPDF_FormControl* pControl = GetControl(i); |
879 if (bDefault) { | 871 if (bDefault) { |
880 bChecked = pControl->IsDefaultChecked(); | 872 bChecked = pControl->IsDefaultChecked(); |
881 } else { | 873 } else { |
882 bChecked = pControl->IsChecked(); | 874 bChecked = pControl->IsChecked(); |
883 } | 875 } |
884 if (bChecked) { | 876 if (bChecked) { |
885 csExport = pControl->GetExportValue(); | 877 csExport = pControl->GetExportValue(); |
886 break; | 878 break; |
887 } | 879 } |
888 } | 880 } |
889 return csExport; | 881 return csExport; |
890 } | 882 } |
891 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, | 883 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, |
892 FX_BOOL bDefault, | 884 FX_BOOL bDefault, |
893 FX_BOOL bNotify) { | 885 FX_BOOL bNotify) { |
894 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 886 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
895 CFX_ByteArray statusArray; | |
896 if (bNotify && m_pForm->m_pFormNotify) { | |
897 SaveCheckedFieldStatus(this, statusArray); | |
898 } | |
899 int iCount = CountControls(); | 887 int iCount = CountControls(); |
900 for (int i = 0; i < iCount; i++) { | 888 for (int i = 0; i < iCount; i++) { |
901 CPDF_FormControl* pControl = GetControl(i); | 889 CPDF_FormControl* pControl = GetControl(i); |
902 CFX_WideString csExport = pControl->GetExportValue(); | 890 CFX_WideString csExport = pControl->GetExportValue(); |
903 if (csExport == value) { | 891 if (csExport == value) { |
904 if (bDefault) { | 892 if (bDefault) { |
905 } else { | 893 } else { |
906 CheckControl(GetControlIndex(pControl), TRUE); | 894 CheckControl(GetControlIndex(pControl), TRUE); |
907 } | 895 } |
908 break; | 896 break; |
909 } else { | 897 } else { |
910 if (bDefault) { | 898 if (bDefault) { |
911 } else { | 899 } else { |
912 CheckControl(GetControlIndex(pControl), FALSE); | 900 CheckControl(GetControlIndex(pControl), FALSE); |
913 } | 901 } |
914 } | 902 } |
915 } | 903 } |
916 if (bNotify && m_pForm->m_pFormNotify) { | 904 if (bNotify && m_pForm->m_pFormNotify) { |
917 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); | 905 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
918 } | 906 } |
919 m_pForm->m_bUpdated = TRUE; | 907 m_pForm->m_bUpdated = TRUE; |
920 return TRUE; | 908 return TRUE; |
921 } | 909 } |
922 int CPDF_FormField::GetTopVisibleIndex() { | 910 int CPDF_FormField::GetTopVisibleIndex() { |
923 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); | 911 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
924 if (!pObj) { | 912 if (!pObj) { |
925 return 0; | 913 return 0; |
926 } | 914 } |
927 return pObj->GetInteger(); | 915 return pObj->GetInteger(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") | 1083 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") |
1096 ->GetDictBy("Font") | 1084 ->GetDictBy("Font") |
1097 ->GetDictBy(font_name); | 1085 ->GetDictBy(font_name); |
1098 | 1086 |
1099 if (!pFontDict) { | 1087 if (!pFontDict) { |
1100 return; | 1088 return; |
1101 } | 1089 } |
1102 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 1090 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
1103 m_FontSize = FX_atof(syntax.GetWord()); | 1091 m_FontSize = FX_atof(syntax.GetWord()); |
1104 } | 1092 } |
OLD | NEW |