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 #include "third_party/base/stl_util.h" |
9 | 10 |
10 const int nMaxRecursion = 32; | 11 const int nMaxRecursion = 32; |
11 | 12 |
12 class CFieldNameExtractor { | 13 class CFieldNameExtractor { |
13 public: | 14 public: |
14 explicit CFieldNameExtractor(const CFX_WideString& full_name) { | 15 explicit CFieldNameExtractor(const CFX_WideString& full_name) { |
15 m_pStart = full_name.c_str(); | 16 m_pStart = full_name.c_str(); |
16 m_pEnd = m_pStart + full_name.GetLength(); | 17 m_pEnd = m_pStart + full_name.GetLength(); |
17 m_pCur = m_pStart; | 18 m_pCur = m_pStart; |
18 } | 19 } |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 bool bNotify) { | 840 bool bNotify) { |
840 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 841 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
841 return false; | 842 return false; |
842 | 843 |
843 int nCount = m_pFieldTree->m_Root.CountFields(); | 844 int nCount = m_pFieldTree->m_Root.CountFields(); |
844 for (int i = 0; i < nCount; ++i) { | 845 for (int i = 0; i < nCount; ++i) { |
845 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 846 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
846 if (!pField) | 847 if (!pField) |
847 continue; | 848 continue; |
848 | 849 |
849 auto it = std::find(fields.begin(), fields.end(), pField); | 850 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) |
850 if (bIncludeOrExclude == (it != fields.end())) | |
851 pField->ResetField(bNotify); | 851 pField->ResetField(bNotify); |
852 } | 852 } |
853 if (bNotify && m_pFormNotify) | 853 if (bNotify && m_pFormNotify) |
854 m_pFormNotify->AfterFormReset(this); | 854 m_pFormNotify->AfterFormReset(this); |
855 return true; | 855 return true; |
856 } | 856 } |
857 | 857 |
858 bool CPDF_InterForm::ResetForm(bool bNotify) { | 858 bool CPDF_InterForm::ResetForm(bool bNotify) { |
859 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 859 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
860 return false; | 860 return false; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 if (iType == CPDF_FormField::PushButton || | 1012 if (iType == CPDF_FormField::PushButton || |
1013 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { | 1013 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { |
1014 continue; | 1014 continue; |
1015 } | 1015 } |
1016 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1016 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1017 // TODO(thestig): Look up these magic numbers and add constants for them. | 1017 // TODO(thestig): Look up these magic numbers and add constants for them. |
1018 if (dwFlags & 0x04) | 1018 if (dwFlags & 0x04) |
1019 continue; | 1019 continue; |
1020 | 1020 |
1021 bool bFind = true; | 1021 bool bFind = true; |
1022 if (fields) { | 1022 if (fields) |
1023 auto it = std::find(fields->begin(), fields->end(), pField); | 1023 bFind = pdfium::ContainsValue(*fields, pField); |
1024 bFind = (it != fields->end()); | |
1025 } | |
1026 if (bIncludeOrExclude == bFind) { | 1024 if (bIncludeOrExclude == bFind) { |
1027 CPDF_Dictionary* pFieldDict = pField->m_pDict; | 1025 CPDF_Dictionary* pFieldDict = pField->m_pDict; |
1028 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { | 1026 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { |
1029 return pField; | 1027 return pField; |
1030 } | 1028 } |
1031 } | 1029 } |
1032 } | 1030 } |
1033 return nullptr; | 1031 return nullptr; |
1034 } | 1032 } |
1035 | 1033 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 int nCount = m_pFieldTree->m_Root.CountFields(); | 1066 int nCount = m_pFieldTree->m_Root.CountFields(); |
1069 for (int i = 0; i < nCount; i++) { | 1067 for (int i = 0; i < nCount; i++) { |
1070 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1068 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
1071 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { | 1069 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { |
1072 continue; | 1070 continue; |
1073 } | 1071 } |
1074 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1072 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1075 if (dwFlags & 0x04) | 1073 if (dwFlags & 0x04) |
1076 continue; | 1074 continue; |
1077 | 1075 |
1078 auto it = std::find(fields.begin(), fields.end(), pField); | 1076 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
1079 if (bIncludeOrExclude == (it != fields.end())) { | |
1080 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) | 1077 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) |
1081 continue; | 1078 continue; |
1082 | 1079 |
1083 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); | 1080 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); |
1084 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; | 1081 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; |
1085 pFieldDict->SetAt("T", new CPDF_String(fullname)); | 1082 pFieldDict->SetAt("T", new CPDF_String(fullname)); |
1086 if (pField->GetType() == CPDF_FormField::CheckBox || | 1083 if (pField->GetType() == CPDF_FormField::CheckBox || |
1087 pField->GetType() == CPDF_FormField::RadioButton) { | 1084 pField->GetType() == CPDF_FormField::RadioButton) { |
1088 CFX_WideString csExport = pField->GetCheckValue(FALSE); | 1085 CFX_WideString csExport = pField->GetCheckValue(FALSE); |
1089 CFX_ByteString csBExport = PDF_EncodeText(csExport); | 1086 CFX_ByteString csBExport = PDF_EncodeText(csExport); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 FDF_ImportField(pField, L"", bNotify); | 1227 FDF_ImportField(pField, L"", bNotify); |
1231 } | 1228 } |
1232 if (bNotify && m_pFormNotify) { | 1229 if (bNotify && m_pFormNotify) { |
1233 m_pFormNotify->AfterFormImportData(this); | 1230 m_pFormNotify->AfterFormImportData(this); |
1234 } | 1231 } |
1235 return TRUE; | 1232 return TRUE; |
1236 } | 1233 } |
1237 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { | 1234 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { |
1238 m_pFormNotify = (CPDF_FormNotify*)pNotify; | 1235 m_pFormNotify = (CPDF_FormNotify*)pNotify; |
1239 } | 1236 } |
OLD | NEW |