Index: core/src/fpdfdoc/doc_form.cpp |
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp |
index 5cc2a66a89c3817a8b53dfed18708c3588cb5ada..b24fc6bf80054edb06db15f30a5fc1fe5d056ca7 100644 |
--- a/core/src/fpdfdoc/doc_form.cpp |
+++ b/core/src/fpdfdoc/doc_form.cpp |
@@ -9,9 +9,9 @@ |
const int nMaxRecursion = 32; |
-class _CFieldNameExtractor { |
+class CFieldNameExtractor { |
public: |
- _CFieldNameExtractor(const CFX_WideString& full_name) { |
+ explicit CFieldNameExtractor(const CFX_WideString& full_name) { |
m_pStart = full_name.c_str(); |
m_pEnd = m_pStart + full_name.GetLength(); |
m_pCur = m_pStart; |
@@ -151,7 +151,7 @@ void CFieldTree::SetField(const CFX_WideString& full_name, |
if (full_name == L"") { |
return; |
} |
- _CFieldNameExtractor name_extractor(full_name); |
+ CFieldNameExtractor name_extractor(full_name); |
const FX_WCHAR* pName; |
FX_STRSIZE nLength; |
name_extractor.GetNext(pName, nLength); |
@@ -173,7 +173,7 @@ CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { |
if (full_name == L"") { |
return NULL; |
} |
- _CFieldNameExtractor name_extractor(full_name); |
+ CFieldNameExtractor name_extractor(full_name); |
const FX_WCHAR* pName; |
FX_STRSIZE nLength; |
name_extractor.GetNext(pName, nLength); |
@@ -190,7 +190,7 @@ CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { |
if (full_name == L"") { |
return NULL; |
} |
- _CFieldNameExtractor name_extractor(full_name); |
+ CFieldNameExtractor name_extractor(full_name); |
const FX_WCHAR* pName; |
FX_STRSIZE nLength; |
name_extractor.GetNext(pName, nLength); |
@@ -219,7 +219,7 @@ CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) { |
if (full_name == L"") { |
return NULL; |
} |
- _CFieldNameExtractor name_extractor(full_name); |
+ CFieldNameExtractor name_extractor(full_name); |
const FX_WCHAR* pName; |
FX_STRSIZE nLength; |
name_extractor.GetNext(pName, nLength); |
@@ -765,19 +765,7 @@ void CPDF_InterForm::GetAllFieldNames(CFX_WideStringArray& allFieldNames) { |
} |
} |
} |
-FX_BOOL CPDF_InterForm::IsValidFormField(const void* pField) { |
- if (pField == NULL) { |
- return FALSE; |
- } |
- int nCount = m_pFieldTree->m_Root.CountFields(); |
- for (int i = 0; i < nCount; i++) { |
- CPDF_FormField* pFormField = m_pFieldTree->m_Root.GetField(i); |
- if (pField == pFormField) { |
- return TRUE; |
- } |
- } |
- return FALSE; |
-} |
+ |
CPDF_FormField* CPDF_InterForm::GetFieldByDict( |
CPDF_Dictionary* pFieldDict) const { |
if (pFieldDict == NULL) { |
@@ -946,58 +934,51 @@ int CPDF_InterForm::GetFormAlignment() { |
} |
return m_pFormDict->GetInteger("Q", 0); |
} |
-FX_BOOL CPDF_InterForm::ResetForm(const CFX_PtrArray& fields, |
- FX_BOOL bIncludeOrExclude, |
- FX_BOOL bNotify) { |
- if (bNotify && m_pFormNotify != NULL) { |
+ |
+bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, |
+ bool bIncludeOrExclude, |
+ bool bNotify) { |
+ if (bNotify && m_pFormNotify) { |
int iRet = m_pFormNotify->BeforeFormReset(this); |
Tom Sepez
2015/11/09 21:25:31
nit: local not needed. This returns an int, right
Lei Zhang
2015/11/09 22:45:28
Done.
|
if (iRet < 0) { |
- return FALSE; |
+ return false; |
} |
} |
int nCount = m_pFieldTree->m_Root.CountFields(); |
- for (int i = 0; i < nCount; i++) { |
+ for (int i = 0; i < nCount; ++i) { |
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
- if (pField == NULL) { |
+ if (!pField) |
continue; |
- } |
- FX_BOOL bFind = FALSE; |
- int iCount = fields.GetSize(); |
- for (int i = 0; i < iCount; i++) { |
- if (pField == (CPDF_FormField*)fields[i]) { |
- bFind = TRUE; |
- break; |
- } |
- } |
- if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { |
+ |
+ auto it = std::find(fields.begin(), fields.end(), pField); |
+ if (bIncludeOrExclude == (it != fields.end())) |
pField->ResetField(bNotify); |
- } |
} |
- if (bNotify && m_pFormNotify != NULL) { |
+ if (bNotify && m_pFormNotify) |
m_pFormNotify->AfterFormReset(this); |
- } |
- return TRUE; |
+ return true; |
} |
-FX_BOOL CPDF_InterForm::ResetForm(FX_BOOL bNotify) { |
- if (bNotify && m_pFormNotify != NULL) { |
+ |
+bool CPDF_InterForm::ResetForm(bool bNotify) { |
+ if (bNotify && m_pFormNotify) { |
int iRet = m_pFormNotify->BeforeFormReset(this); |
Tom Sepez
2015/11/09 21:25:31
ditto
Lei Zhang
2015/11/09 22:45:28
Done. return false, even.
|
if (iRet < 0) { |
return FALSE; |
} |
} |
int nCount = m_pFieldTree->m_Root.CountFields(); |
- for (int i = 0; i < nCount; i++) { |
+ for (int i = 0; i < nCount; ++i) { |
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
- if (pField == NULL) { |
+ if (!pField) |
continue; |
- } |
+ |
pField->ResetField(bNotify); |
} |
- if (bNotify && m_pFormNotify != NULL) { |
+ if (bNotify && m_pFormNotify) |
m_pFormNotify->AfterFormReset(this); |
- } |
- return TRUE; |
+ return true; |
} |
+ |
void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { |
if (nLevel > nMaxRecursion) { |
return; |
@@ -1126,52 +1107,59 @@ CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, |
((CPDF_FormField*)pField)->m_ControlList.Add(pControl); |
return pControl; |
} |
+ |
CPDF_FormField* CPDF_InterForm::CheckRequiredFields( |
- const CFX_PtrArray* fields, |
+ const std::vector<CPDF_FormField*>* fields, |
FX_BOOL bIncludeOrExclude) const { |
int nCount = m_pFieldTree->m_Root.CountFields(); |
- for (int i = 0; i < nCount; i++) { |
+ for (int i = 0; i < nCount; ++i) { |
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
- if (pField == NULL) { |
+ if (!pField) |
continue; |
- } |
+ |
int32_t iType = pField->GetType(); |
if (iType == CPDF_FormField::PushButton || |
iType == CPDF_FormField::CheckBox || iType == CPDF_FormField::ListBox) { |
continue; |
} |
FX_DWORD dwFlags = pField->GetFieldFlags(); |
- if (dwFlags & 0x04) { |
+ if (dwFlags & 0x04) |
Tom Sepez
2015/11/09 21:25:31
nit: magic number.
Lei Zhang
2015/11/09 22:45:28
Added a TODO.
|
continue; |
+ |
+ bool bFind = true; |
+ if (fields) { |
+ auto it = std::find(fields->begin(), fields->end(), pField); |
+ bFind = (it != fields->end()); |
} |
- FX_BOOL bFind = TRUE; |
- if (fields != NULL) { |
- bFind = fields->Find(pField, 0) >= 0; |
- } |
- if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { |
+ if (bIncludeOrExclude == bFind) { |
CPDF_Dictionary* pFieldDict = pField->m_pDict; |
if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { |
return pField; |
} |
} |
} |
- return NULL; |
+ return nullptr; |
} |
+ |
CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
- FX_BOOL bSimpleFileSpec) const { |
- CFX_PtrArray fields; |
+ bool bSimpleFileSpec) const { |
+ std::vector<CPDF_FormField*> fields; |
int nCount = m_pFieldTree->m_Root.CountFields(); |
- for (int i = 0; i < nCount; i++) { |
+ for (int i = 0; i < nCount; ++i) { |
CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
Tom Sepez
2015/11/09 21:25:31
nit: local not needed.
Lei Zhang
2015/11/09 22:45:28
Done.
|
- fields.Add(pField); |
+ fields.push_back(pField); |
} |
- return ExportToFDF(pdf_path, fields, TRUE, bSimpleFileSpec); |
+ return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); |
} |
+ |
+// TODO(thestig): Fix this. |
Tom Sepez
2015/11/09 21:25:31
nit: by fix this, you mean "move to header"?
Lei Zhang
2015/11/09 22:45:28
Yes, another day.
|
CFX_WideString FILESPEC_EncodeFileName(const CFX_WideStringC& filepath); |
-CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
- CFX_PtrArray& fields, |
- FX_BOOL bIncludeOrExclude, |
- FX_BOOL bSimpleFileSpec) const { |
+ |
+CFDF_Document* CPDF_InterForm::ExportToFDF( |
+ const CFX_WideStringC& pdf_path, |
+ const std::vector<CPDF_FormField*>& fields, |
+ bool bIncludeOrExclude, |
+ bool bSimpleFileSpec) const { |
CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); |
if (pDoc == NULL) { |
return NULL; |
@@ -1204,8 +1192,8 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, |
if (dwFlags & 0x04) { |
continue; |
} |
- FX_BOOL bFind = fields.Find(pField, 0) >= 0; |
- if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { |
+ auto it = std::find(fields.begin(), fields.end(), pField); |
+ if (bIncludeOrExclude == (it != fields.end())) { |
if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) { |
Tom Sepez
2015/11/09 21:25:31
nit: magic number.
Lei Zhang
2015/11/09 22:45:28
Acknowledged.
|
continue; |
} |