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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 bool bNotify) { | 825 bool bNotify) { |
825 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 826 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
826 return false; | 827 return false; |
827 | 828 |
828 int nCount = m_pFieldTree->m_Root.CountFields(); | 829 int nCount = m_pFieldTree->m_Root.CountFields(); |
829 for (int i = 0; i < nCount; ++i) { | 830 for (int i = 0; i < nCount; ++i) { |
830 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 831 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
831 if (!pField) | 832 if (!pField) |
832 continue; | 833 continue; |
833 | 834 |
834 auto it = std::find(fields.begin(), fields.end(), pField); | 835 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) |
835 if (bIncludeOrExclude == (it != fields.end())) | |
836 pField->ResetField(bNotify); | 836 pField->ResetField(bNotify); |
837 } | 837 } |
838 if (bNotify && m_pFormNotify) | 838 if (bNotify && m_pFormNotify) |
839 m_pFormNotify->AfterFormReset(this); | 839 m_pFormNotify->AfterFormReset(this); |
840 return true; | 840 return true; |
841 } | 841 } |
842 | 842 |
843 bool CPDF_InterForm::ResetForm(bool bNotify) { | 843 bool CPDF_InterForm::ResetForm(bool bNotify) { |
844 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) | 844 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) |
845 return false; | 845 return false; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 if (iType == CPDF_FormField::PushButton || | 997 if (iType == CPDF_FormField::PushButton || |
998 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { | 998 iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { |
999 continue; | 999 continue; |
1000 } | 1000 } |
1001 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1001 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1002 // TODO(thestig): Look up these magic numbers and add constants for them. | 1002 // TODO(thestig): Look up these magic numbers and add constants for them. |
1003 if (dwFlags & 0x04) | 1003 if (dwFlags & 0x04) |
1004 continue; | 1004 continue; |
1005 | 1005 |
1006 bool bFind = true; | 1006 bool bFind = true; |
1007 if (fields) { | 1007 if (fields) |
1008 auto it = std::find(fields->begin(), fields->end(), pField); | 1008 bFind = pdfium::ContainsValue(*fields, pField); |
1009 bFind = (it != fields->end()); | |
1010 } | |
1011 if (bIncludeOrExclude == bFind) { | 1009 if (bIncludeOrExclude == bFind) { |
1012 CPDF_Dictionary* pFieldDict = pField->m_pDict; | 1010 CPDF_Dictionary* pFieldDict = pField->m_pDict; |
1013 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { | 1011 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { |
1014 return pField; | 1012 return pField; |
1015 } | 1013 } |
1016 } | 1014 } |
1017 } | 1015 } |
1018 return nullptr; | 1016 return nullptr; |
1019 } | 1017 } |
1020 | 1018 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 int nCount = m_pFieldTree->m_Root.CountFields(); | 1051 int nCount = m_pFieldTree->m_Root.CountFields(); |
1054 for (int i = 0; i < nCount; i++) { | 1052 for (int i = 0; i < nCount; i++) { |
1055 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1053 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
1056 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { | 1054 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { |
1057 continue; | 1055 continue; |
1058 } | 1056 } |
1059 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1057 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1060 if (dwFlags & 0x04) | 1058 if (dwFlags & 0x04) |
1061 continue; | 1059 continue; |
1062 | 1060 |
1063 auto it = std::find(fields.begin(), fields.end(), pField); | 1061 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { |
1064 if (bIncludeOrExclude == (it != fields.end())) { | |
1065 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) | 1062 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) |
1066 continue; | 1063 continue; |
1067 | 1064 |
1068 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); | 1065 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); |
1069 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; | 1066 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; |
1070 pFieldDict->SetAt("T", new CPDF_String(fullname)); | 1067 pFieldDict->SetAt("T", new CPDF_String(fullname)); |
1071 if (pField->GetType() == CPDF_FormField::CheckBox || | 1068 if (pField->GetType() == CPDF_FormField::CheckBox || |
1072 pField->GetType() == CPDF_FormField::RadioButton) { | 1069 pField->GetType() == CPDF_FormField::RadioButton) { |
1073 CFX_WideString csExport = pField->GetCheckValue(FALSE); | 1070 CFX_WideString csExport = pField->GetCheckValue(FALSE); |
1074 CFX_ByteString csBExport = PDF_EncodeText(csExport); | 1071 CFX_ByteString csBExport = PDF_EncodeText(csExport); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 FDF_ImportField(pField, L"", bNotify); | 1212 FDF_ImportField(pField, L"", bNotify); |
1216 } | 1213 } |
1217 if (bNotify && m_pFormNotify) { | 1214 if (bNotify && m_pFormNotify) { |
1218 m_pFormNotify->AfterFormImportData(this); | 1215 m_pFormNotify->AfterFormImportData(this); |
1219 } | 1216 } |
1220 return TRUE; | 1217 return TRUE; |
1221 } | 1218 } |
1222 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { | 1219 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { |
1223 m_pFormNotify = (CPDF_FormNotify*)pNotify; | 1220 m_pFormNotify = (CPDF_FormNotify*)pNotify; |
1224 } | 1221 } |
OLD | NEW |