diff options
author | Lei Zhang <thestig@chromium.org> | 2015-11-10 09:38:57 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-11-10 09:38:57 -0800 |
commit | d88a364c1c79b294b980c20ebc9356ea42635bff (patch) | |
tree | bb44b0a75a3671ba3e305e3d812dcc098144e851 | |
parent | b553bcb6a8e69de61f3b4abd257ee3161aa752c6 (diff) | |
download | pdfium-d88a364c1c79b294b980c20ebc9356ea42635bff.tar.xz |
Merge to XFA: Remove CFX_PtrArray usage in fpdfsdk.
TBR=tsepez@chromium.org
Review URL: https://codereview.chromium.org/1430213002 .
(cherry picked from commit 8deeacd23872ecc132a0a678e344a018b5114a3a)
Review URL: https://codereview.chromium.org/1416113010 .
-rw-r--r-- | core/include/fpdfdoc/fpdf_doc.h | 50 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_action.cpp | 42 | ||||
-rw-r--r-- | core/src/fpdfdoc/doc_form.cpp | 173 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_baseform.h | 13 | ||||
-rw-r--r-- | fpdfsdk/include/jsapi/fxjs_v8.h | 8 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_baseform.cpp | 166 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Document.cpp | 99 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Field.cpp | 876 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/Field.h | 18 | ||||
-rw-r--r-- | fpdfsdk/src/jsapi/fxjs_v8.cpp | 19 |
10 files changed, 569 insertions, 895 deletions
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index e593471e53..6fcb671826 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -44,7 +44,7 @@ class CXML_Element; class CPDF_NameTree { public: - CPDF_NameTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; } + explicit CPDF_NameTree(CPDF_Dictionary* pRoot) { m_pRoot = pRoot; } CPDF_NameTree(CPDF_Document* pDoc, const CFX_ByteStringC& category); @@ -66,7 +66,7 @@ class CPDF_NameTree { }; class CPDF_BookmarkTree { public: - CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {} + explicit CPDF_BookmarkTree(CPDF_Document* pDoc) : m_pDocument(pDoc) {} CPDF_Bookmark GetFirstChild(const CPDF_Bookmark& parent) const; @@ -130,7 +130,7 @@ class CPDF_OCContext : public IPDF_OCContext { public: enum UsageType { View = 0, Design, Print, Export }; - CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType = View); + explicit CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType = View); ~CPDF_OCContext() override; CPDF_Document* GetDocument() const { return m_pDocument; } @@ -165,15 +165,17 @@ class CPDF_OCContext : public IPDF_OCContext { class CPDF_ActionFields { public: + // TODO(thestig): Examine why this cannot be explicit. CPDF_ActionFields(const CPDF_Action* pAction) { m_pAction = (CPDF_Action*)pAction; } + // TODO(thestig): Replace this. operator CPDF_Action*() const { return m_pAction; } FX_DWORD GetFieldsCount() const; - void GetAllFields(CFX_PtrArray& fieldObjects) const; + std::vector<CPDF_Object*> GetAllFields() const; CPDF_Object* GetField(FX_DWORD iIndex) const; @@ -263,6 +265,7 @@ class CPDF_Action { }; class CPDF_AAction { public: + // TODO(thestig): Examine why this cannot be explicit. CPDF_AAction(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } operator CPDF_Dictionary*() const { return m_pDict; } @@ -303,7 +306,7 @@ class CPDF_AAction { }; class CPDF_DocJSActions { public: - CPDF_DocJSActions(CPDF_Document* pDoc); + explicit CPDF_DocJSActions(CPDF_Document* pDoc); int CountJSActions() const; @@ -316,13 +319,13 @@ class CPDF_DocJSActions { CPDF_Document* GetDocument() const { return m_pDocument; } protected: - CPDF_Document* m_pDocument; + CPDF_Document* const m_pDocument; }; class CPDF_FileSpec { public: CPDF_FileSpec(); - CPDF_FileSpec(CPDF_Object* pObj) { m_pObj = pObj; } + explicit CPDF_FileSpec(CPDF_Object* pObj) { m_pObj = pObj; } operator CPDF_Object*() const { return m_pObj; } @@ -473,6 +476,7 @@ class CPDF_AnnotList { #define COLORTYPE_CMYK 3 class CPDF_DefaultAppearance { public: + // TODO(thestig): Examine why this cannot be explicit. CPDF_DefaultAppearance(const CFX_ByteString& csDA = "") { m_csDA = csDA; } CPDF_DefaultAppearance(const CPDF_DefaultAppearance& cDA) { @@ -579,8 +583,6 @@ class CPDF_InterForm : public CFX_PrivateData { void GetAllFieldNames(CFX_WideStringArray& allFieldNames); - FX_BOOL IsValidFormField(const void* pField); - CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const; CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage, @@ -644,24 +646,25 @@ class CPDF_InterForm : public CFX_PrivateData { int GetFormAlignment(); - CPDF_FormField* CheckRequiredFields(const CFX_PtrArray* fields = NULL, - FX_BOOL bIncludeOrExclude = TRUE) const; + CPDF_FormField* CheckRequiredFields( + const std::vector<CPDF_FormField*>* fields, + bool bIncludeOrExclude) const; CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, - FX_BOOL bSimpleFileSpec = FALSE) const; + bool bSimpleFileSpec = false) const; CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, - CFX_PtrArray& fields, - FX_BOOL bIncludeOrExclude = TRUE, - FX_BOOL bSimpleFileSpec = FALSE) const; + const std::vector<CPDF_FormField*>& fields, + bool bIncludeOrExclude = true, + bool bSimpleFileSpec = false) const; FX_BOOL ImportFromFDF(const CFDF_Document* pFDFDoc, FX_BOOL bNotify = FALSE); - FX_BOOL ResetForm(const CFX_PtrArray& fields, - FX_BOOL bIncludeOrExclude = TRUE, - FX_BOOL bNotify = FALSE); + bool ResetForm(const std::vector<CPDF_FormField*>& fields, + bool bIncludeOrExclude = true, + bool bNotify = false); - FX_BOOL ResetForm(FX_BOOL bNotify = FALSE); + bool ResetForm(bool bNotify = false); CPDF_FormNotify* GetFormNotify() const { return m_pFormNotify; } @@ -891,6 +894,7 @@ CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, int nLevel = 0); class CPDF_IconFit { public: + // TODO(thestig): Examine why this cannot be explicit. CPDF_IconFit(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } operator CPDF_Dictionary*() const { return m_pDict; } @@ -1064,7 +1068,7 @@ class CPDF_FormNotify { FX_BOOL FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); class CPDF_PageLabel { public: - CPDF_PageLabel(CPDF_Document* pDocument) { m_pDocument = pDocument; } + explicit CPDF_PageLabel(CPDF_Document* pDocument) { m_pDocument = pDocument; } CFX_WideString GetLabel(int nPage) const; @@ -1089,7 +1093,7 @@ class CPDF_Metadata { class CPDF_ViewerPreferences { public: - CPDF_ViewerPreferences(CPDF_Document* pDoc); + explicit CPDF_ViewerPreferences(CPDF_Document* pDoc); ~CPDF_ViewerPreferences(); @@ -1104,10 +1108,12 @@ class CPDF_ViewerPreferences { CFX_ByteString Duplex() const; protected: - CPDF_Document* m_pDoc; + CPDF_Document* const m_pDoc; }; + class CPDF_ApSettings { public: + // TODO(thestig): Examine why this cannot be explicit. CPDF_ApSettings(CPDF_Dictionary* pDict = NULL) { m_pDict = pDict; } operator CPDF_Dictionary*() const { return m_pDict; } diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index d685f64cae..3d439ff570 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -111,37 +111,39 @@ FX_DWORD CPDF_ActionFields::GetFieldsCount() const { return pArray->GetCount(); return 0; } -void CPDF_ActionFields::GetAllFields(CFX_PtrArray& fieldObjects) const { - fieldObjects.RemoveAll(); - if (m_pAction == NULL) { - return; - } + +std::vector<CPDF_Object*> CPDF_ActionFields::GetAllFields() const { + std::vector<CPDF_Object*> fields; + if (!m_pAction) + return fields; + CPDF_Dictionary* pDict = m_pAction->GetDict(); - if (pDict == NULL) { - return; - } + if (!pDict) + return fields; + CFX_ByteString csType = pDict->GetString("S"); - CPDF_Object* pFields = NULL; - if (csType == "Hide") { + CPDF_Object* pFields; + if (csType == "Hide") pFields = pDict->GetElementValue("T"); - } else { + else pFields = pDict->GetArray("Fields"); - } if (!pFields) - return; + return fields; if (pFields->IsDictionary() || pFields->IsString()) { - fieldObjects.Add(pFields); + fields.push_back(pFields); } else if (CPDF_Array* pArray = pFields->AsArray()) { FX_DWORD iCount = pArray->GetCount(); - for (FX_DWORD i = 0; i < iCount; i++) { + for (FX_DWORD i = 0; i < iCount; ++i) { CPDF_Object* pObj = pArray->GetElementValue(i); - if (pObj != NULL) { - fieldObjects.Add(pObj); + if (pObj) { + fields.push_back(pObj); } } } + return fields; } + CPDF_Object* CPDF_ActionFields::GetField(FX_DWORD iIndex) const { if (m_pAction == NULL) { return NULL; @@ -291,9 +293,9 @@ CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, eType = (AActionType)i; return CPDF_Action(pDict); } -CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) { - m_pDocument = pDoc; -} + +CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} + int CPDF_DocJSActions::CountJSActions() const { ASSERT(m_pDocument != NULL); CPDF_NameTree name_tree(m_pDocument, FX_BSTRC("JavaScript")); diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp index 5cc2a66a89..8d8a836cab 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,45 @@ 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) { - int iRet = m_pFormNotify->BeforeFormReset(this); - if (iRet < 0) { - return FALSE; - } - } + +bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, + bool bIncludeOrExclude, + bool bNotify) { + if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 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; - } - 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) { - int iRet = m_pFormNotify->BeforeFormReset(this); - if (iRet < 0) { - return FALSE; - } - } + +bool CPDF_InterForm::ResetForm(bool bNotify) { + if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 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 +1101,58 @@ 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, - FX_BOOL bIncludeOrExclude) const { + const std::vector<CPDF_FormField*>* fields, + 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) { + // TODO(thestig): Look up these magic numbers and add constants for them. + if (dwFlags & 0x04) 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++) { - CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); - fields.Add(pField); - } - return ExportToFDF(pdf_path, fields, TRUE, bSimpleFileSpec); + for (int i = 0; i < nCount; ++i) + fields.push_back(m_pFieldTree->m_Root.GetField(i)); + return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); } + +// TODO(thestig): Fix this. 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; @@ -1201,23 +1182,23 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, continue; } FX_DWORD dwFlags = pField->GetFieldFlags(); - if (dwFlags & 0x04) { + if (dwFlags & 0x04) continue; - } - FX_BOOL bFind = fields.Find(pField, 0) >= 0; - if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { - if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) { + + auto it = std::find(fields.begin(), fields.end(), pField); + if (bIncludeOrExclude == (it != fields.end())) { + if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty()) continue; - } + CFX_WideString fullname = GetFullName(pField->GetFieldDict()); CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create(); - if (pFieldDict == NULL) { - return NULL; - } + if (!pFieldDict) + return nullptr; + CPDF_String* pString = CPDF_String::Create(fullname); - if (pString == NULL) { + if (!pString) { pFieldDict->Release(); - return NULL; + return nullptr; } pFieldDict->SetAt("T", pString); if (pField->GetType() == CPDF_FormField::CheckBox || @@ -1225,16 +1206,14 @@ CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, CFX_WideString csExport = pField->GetCheckValue(FALSE); CFX_ByteString csBExport = PDF_EncodeText(csExport); CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); - if (pOpt == NULL) { - pFieldDict->SetAtName("V", csBExport); - } else { + if (pOpt) pFieldDict->SetAtString("V", csBExport); - } + else + pFieldDict->SetAtName("V", csBExport); } else { CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); - if (pV != NULL) { + if (pV) pFieldDict->SetAt("V", pV->Clone(TRUE)); - } } pFields->Add(pFieldDict); } diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h index dd119b56b3..788ba5fade 100644 --- a/fpdfsdk/include/fsdk_baseform.h +++ b/fpdfsdk/include/fsdk_baseform.h @@ -242,8 +242,10 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const; CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const; - void GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets); - void GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets); + void GetWidgets(const CFX_WideString& sFieldName, + std::vector<CPDFSDK_Widget*>* widgets) const; + void GetWidgets(CPDF_FormField* pField, + std::vector<CPDFSDK_Widget*>* widgets) const; void AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget); void RemoveMap(CPDF_FormControl* pControl); @@ -284,15 +286,16 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { FX_BOOL DoAction_ResetForm(const CPDF_Action& action); FX_BOOL DoAction_ImportData(const CPDF_Action& action); - void GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields); + std::vector<CPDF_FormField*> GetFieldFromObjects( + const std::vector<CPDF_Object*>& objects) const; FX_BOOL IsValidField(CPDF_Dictionary* pFieldDict); FX_BOOL SubmitFields(const CFX_WideString& csDestination, - const CFX_PtrArray& fields, + const std::vector<CPDF_FormField*>& fields, FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded); FX_BOOL SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded); FX_BOOL ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf); - FX_BOOL ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields, + FX_BOOL ExportFieldsToFDFTextBuf(const std::vector<CPDF_FormField*>& fields, FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf); CFX_WideString GetTemporaryFileName(const CFX_WideString& sFileExt); diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h index 00eb704d93..70518406cb 100644 --- a/fpdfsdk/include/jsapi/fxjs_v8.h +++ b/fpdfsdk/include/jsapi/fxjs_v8.h @@ -16,7 +16,11 @@ #include <v8.h> -#include "core/include/fxcrt/fx_basic.h" +#include <vector> + +#include "core/include/fxcrt/fx_string.h" + +class CFXJS_ObjDefinition; // FXJS_V8 places no restrictions on these two classes; it merely passes them // on to caller-provided methods. @@ -44,7 +48,7 @@ class FXJS_PerIsolateData { static void SetUp(v8::Isolate* pIsolate); static FXJS_PerIsolateData* Get(v8::Isolate* pIsolate); - CFX_PtrArray m_ObjectDefnArray; + std::vector<CFXJS_ObjDefinition*> m_ObjectDefnArray; CFXJSE_RuntimeData* m_pFXJSERuntimeData; protected: diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp index 5c4269e354..06ed0f4c22 100644 --- a/fpdfsdk/src/fsdk_baseform.cpp +++ b/fpdfsdk/src/fsdk_baseform.cpp @@ -15,10 +15,6 @@ #include "../include/javascript/IJavaScript.h" #include "third_party/base/nonstd_unique_ptr.h" -//------------------------------------------------------------------------------------ -//* CPDFSDK_Widget -//------------------------------------------------------------------------------------ - #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01) #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) @@ -1499,9 +1495,9 @@ void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { pEdit->Initialize(); - if (sValue) + if (sValue) { pEdit->SetText(sValue); - else { + } else { int32_t nCurSel = pField->GetSelectedIndex(0); if (nCurSel < 0) @@ -2211,30 +2207,25 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); } -void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, - CFX_PtrArray& widgets) { - ASSERT(m_pInterForm != NULL); - - for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; i++) { +void CPDFSDK_InterForm::GetWidgets( + const CFX_WideString& sFieldName, + std::vector<CPDFSDK_Widget*>* widgets) const { + for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); - ASSERT(pFormField != NULL); - + ASSERT(pFormField); GetWidgets(pFormField, widgets); } } -void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, - CFX_PtrArray& widgets) { - ASSERT(pField != NULL); - - for (int i = 0, isz = pField->CountControls(); i < isz; i++) { +void CPDFSDK_InterForm::GetWidgets( + CPDF_FormField* pField, + std::vector<CPDFSDK_Widget*>* widgets) const { + for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { CPDF_FormControl* pFormCtrl = pField->GetControl(i); - ASSERT(pFormCtrl != NULL); - + ASSERT(pFormCtrl); CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); - if (pWidget) - widgets.Add(pWidget); + widgets->push_back(pWidget); } } @@ -2584,42 +2575,27 @@ FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { ASSERT(action); CPDF_ActionFields af = action.GetWidgets(); - CFX_PtrArray fieldObjects; - af.GetAllFields(fieldObjects); - CFX_PtrArray widgetArray; - CFX_PtrArray fields; - GetFieldFromObjects(fieldObjects, fields); + std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); + std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); FX_BOOL bHide = action.GetHideStatus(); - FX_BOOL bChanged = FALSE; - for (int i = 0, sz = fields.GetSize(); i < sz; i++) { - CPDF_FormField* pField = (CPDF_FormField*)fields[i]; - ASSERT(pField != NULL); - - for (int j = 0, jsz = pField->CountControls(); j < jsz; j++) { - CPDF_FormControl* pControl = pField->GetControl(j); - ASSERT(pControl != NULL); + for (CPDF_FormField* pField : fields) { + for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { + CPDF_FormControl* pControl = pField->GetControl(i); + ASSERT(pControl); if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) { int nFlags = pWidget->GetFlags(); - if (bHide) { - nFlags &= (~ANNOTFLAG_INVISIBLE); - nFlags &= (~ANNOTFLAG_NOVIEW); - nFlags |= (ANNOTFLAG_HIDDEN); - } else { - nFlags &= (~ANNOTFLAG_INVISIBLE); - nFlags &= (~ANNOTFLAG_HIDDEN); - nFlags &= (~ANNOTFLAG_NOVIEW); - } + nFlags &= ~ANNOTFLAG_INVISIBLE; + nFlags &= ~ANNOTFLAG_NOVIEW; + if (bHide) + nFlags |= ANNOTFLAG_HIDDEN; + else + nFlags &= ~ANNOTFLAG_HIDDEN; pWidget->SetFlags(nFlags); - - CPDFSDK_PageView* pPageView = pWidget->GetPageView(); - ASSERT(pPageView != NULL); - - pPageView->UpdateView(pWidget); - + pWidget->GetPageView()->UpdateView(pWidget); bChanged = TRUE; } } @@ -2638,31 +2614,28 @@ FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { if (pActionDict->KeyExist("Fields")) { CPDF_ActionFields af = action.GetWidgets(); FX_DWORD dwFlags = action.GetFlags(); - CFX_PtrArray fieldObjects; - af.GetAllFields(fieldObjects); - - CFX_PtrArray fields; - GetFieldFromObjects(fieldObjects, fields); - if (fields.GetSize() != 0) { - FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01); + std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); + std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); + if (!fields.empty()) { + bool bIncludeOrExclude = !(dwFlags & 0x01); if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) return FALSE; return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE); } } - if (m_pInterForm->CheckRequiredFields()) + if (m_pInterForm->CheckRequiredFields(nullptr, true)) return FALSE; return SubmitForm(sDestination, FALSE); } -FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, - const CFX_PtrArray& fields, - FX_BOOL bIncludeOrExclude, - FX_BOOL bUrlEncoded) { +FX_BOOL CPDFSDK_InterForm::SubmitFields( + const CFX_WideString& csDestination, + const std::vector<CPDF_FormField*>& fields, + FX_BOOL bIncludeOrExclude, + FX_BOOL bUrlEncoded) { CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); - ASSERT(pEnv != NULL); CFX_ByteTextBuf textBuf; ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); @@ -2670,13 +2643,10 @@ FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, uint8_t* pBuffer = textBuf.GetBuffer(); FX_STRSIZE nBufSize = textBuf.GetLength(); - if (bUrlEncoded) { - if (!FDFToURLEncodedData(pBuffer, nBufSize)) - return FALSE; - } + if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) + return FALSE; pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str()); - return TRUE; } @@ -2728,20 +2698,13 @@ FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, return TRUE; } -FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields, - FX_BOOL bIncludeOrExclude, - CFX_ByteTextBuf& textBuf) { - ASSERT(m_pDocument != NULL); - ASSERT(m_pInterForm != NULL); - - CFDF_Document* pFDF = m_pInterForm->ExportToFDF( - m_pDocument->GetPath(), (CFX_PtrArray&)fields, bIncludeOrExclude); - if (!pFDF) - return FALSE; - FX_BOOL bRet = pFDF->WriteBuf(textBuf); - delete pFDF; - - return bRet; +FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( + const std::vector<CPDF_FormField*>& fields, + FX_BOOL bIncludeOrExclude, + CFX_ByteTextBuf& textBuf) { + nonstd::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( + m_pDocument->GetPath(), fields, bIncludeOrExclude)); + return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; } void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, @@ -2829,44 +2792,33 @@ FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { ASSERT(action); CPDF_Dictionary* pActionDict = action.GetDict(); - if (pActionDict->KeyExist("Fields")) { - CPDF_ActionFields af = action.GetWidgets(); - FX_DWORD dwFlags = action.GetFlags(); + if (!pActionDict->KeyExist("Fields")) + return m_pInterForm->ResetForm(true); - CFX_PtrArray fieldObjects; - af.GetAllFields(fieldObjects); - CFX_PtrArray fields; - GetFieldFromObjects(fieldObjects, fields); - return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE); - } + CPDF_ActionFields af = action.GetWidgets(); + FX_DWORD dwFlags = action.GetFlags(); - return m_pInterForm->ResetForm(TRUE); + std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); + std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); + return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); } FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { return FALSE; } -void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, - CFX_PtrArray& fields) { - ASSERT(m_pInterForm != NULL); - - int iCount = objects.GetSize(); - for (int i = 0; i < iCount; i++) { - CPDF_Object* pObject = static_cast<CPDF_Object*>(objects[i]); - if (!pObject) - continue; - - if (pObject->IsString()) { +std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects( + const std::vector<CPDF_Object*>& objects) const { + std::vector<CPDF_FormField*> fields; + for (CPDF_Object* pObject : objects) { + if (pObject && pObject->IsString()) { CFX_WideString csName = pObject->GetUnicodeText(); CPDF_FormField* pField = m_pInterForm->GetField(0, csName); if (pField) - fields.Add(pField); - } else if (pObject->IsDictionary()) { - if (m_pInterForm->IsValidFormField(pObject)) - fields.Add(pObject); + fields.push_back(pField); } } + return fields; } /* ----------------------------- CPDF_FormNotify ----------------------------- diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp index e128860863..43d2504150 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -520,35 +520,30 @@ FX_BOOL Document::removeField(IJS_Context* cc, (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray widgets; - pInterForm->GetWidgets(sFieldName, widgets); + std::vector<CPDFSDK_Widget*> widgets; + pInterForm->GetWidgets(sFieldName, &widgets); - int nSize = widgets.GetSize(); - - if (nSize > 0) { - for (int i = 0; i < nSize; i++) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i]; - ASSERT(pWidget != NULL); - - CPDF_Rect rcAnnot = pWidget->GetRect(); - rcAnnot.left -= 1; - rcAnnot.bottom -= 1; - rcAnnot.right += 1; - rcAnnot.top += 1; + if (widgets.empty()) + return TRUE; - CFX_RectArray aRefresh; - aRefresh.Add(rcAnnot); + for (CPDFSDK_Widget* pWidget : widgets) { + CPDF_Rect rcAnnot = pWidget->GetRect(); + --rcAnnot.left; + --rcAnnot.bottom; + ++rcAnnot.right; + ++rcAnnot.top; - CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage(); - ASSERT(pPage != NULL); + CFX_RectArray aRefresh; + aRefresh.Add(rcAnnot); - CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); - pPageView->DeleteAnnot(pWidget); + CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage(); + ASSERT(pPage); - pPageView->UpdateRects(aRefresh); - } - m_pDocument->SetChangeMark(); + CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); + pPageView->DeleteAnnot(pWidget); + pPageView->UpdateRects(aRefresh); } + m_pDocument->SetChangeMark(); return TRUE; } @@ -572,33 +567,33 @@ FX_BOOL Document::resetForm(IJS_Context* cc, CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CJS_Array aName(pRuntime); - if (params.size() > 0) { - switch (params[0].GetType()) { - default: - aName.Attach(params[0].ToV8Array()); - break; - case CJS_Value::VT_string: - aName.SetElement(0, params[0]); - break; - } + // TODO(thestig) Convert CJS_Parameters to a std::vector and use .empty(). + if (params.size() <= 0) { + pPDFForm->ResetForm(TRUE); + m_pDocument->SetChangeMark(); + return TRUE; + } - CFX_PtrArray aFields; + switch (params[0].GetType()) { + default: + aName.Attach(params[0].ToV8Array()); + break; + case CJS_Value::VT_string: + aName.SetElement(0, params[0]); + break; + } - for (int i = 0, isz = aName.GetLength(); i < isz; i++) { - CJS_Value valElement(pRuntime); - aName.GetElement(i, valElement); - CFX_WideString swVal = valElement.ToCFXWideString(); - for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; j++) { - aFields.Add((void*)pPDFForm->GetField(j, swVal)); - } - } + std::vector<CPDF_FormField*> aFields; + for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { + CJS_Value valElement(pRuntime); + aName.GetElement(i, valElement); + CFX_WideString swVal = valElement.ToCFXWideString(); + for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) + aFields.push_back(pPDFForm->GetField(j, swVal)); + } - if (aFields.GetSize() > 0) { - pPDFForm->ResetForm(aFields, TRUE, TRUE); - m_pDocument->SetChangeMark(); - } - } else { - pPDFForm->ResetForm(TRUE); + if (!aFields.empty()) { + pPDFForm->ResetForm(aFields, TRUE, TRUE); m_pDocument->SetChangeMark(); } @@ -663,7 +658,7 @@ FX_BOOL Document::submitForm(IJS_Context* cc, CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); FX_BOOL bAll = (aFields.GetLength() == 0); if (bAll && bEmpty) { - if (pPDFInterForm->CheckRequiredFields()) { + if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { pRuntime->BeginBlock(); pInterForm->SubmitForm(strURL, FALSE); pRuntime->EndBlock(); @@ -671,8 +666,8 @@ FX_BOOL Document::submitForm(IJS_Context* cc, return TRUE; } - CFX_PtrArray fieldObjects; - for (int i = 0, sz = aFields.GetLength(); i < sz; i++) { + std::vector<CPDF_FormField*> fieldObjects; + for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { CJS_Value valName(pRuntime); aFields.GetElement(i, valName); @@ -683,11 +678,11 @@ FX_BOOL Document::submitForm(IJS_Context* cc, if (!bEmpty && pField->GetValue().IsEmpty()) continue; - fieldObjects.Add(pField); + fieldObjects.push_back(pField); } } - if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) { + if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { pRuntime->BeginBlock(); pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); pRuntime->EndBlock(); diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index f3d12b479a..1697b34337 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -114,7 +114,7 @@ void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); Field* pField = static_cast<Field*>(GetEmbedObject()); pField->SetIsolate(pRuntime->GetIsolate()); -}; +} Field::Field(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), @@ -193,30 +193,22 @@ FX_BOOL Field::AttachField(Document* pDocument, return TRUE; } -void Field::GetFormFields(CPDFSDK_Document* pDocument, - const CFX_WideString& csFieldName, - CFX_PtrArray& FieldArray) { - ASSERT(pDocument != NULL); - +std::vector<CPDF_FormField*> Field::GetFormFields( + CPDFSDK_Document* pDocument, + const CFX_WideString& csFieldName) { + std::vector<CPDF_FormField*> fields; CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm(); - ASSERT(pReaderInterForm != NULL); - CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); - ASSERT(pInterForm != NULL); - - ASSERT(FieldArray.GetSize() == 0); - - for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; i++) { + for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) { if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName)) - FieldArray.Add((void*)pFormField); + fields.push_back(pFormField); } + return fields; } -void Field::GetFormFields(const CFX_WideString& csFieldName, - CFX_PtrArray& FieldArray) { - ASSERT(m_pDocument != NULL); - - Field::GetFormFields(m_pDocument, csFieldName, FieldArray); +std::vector<CPDF_FormField*> Field::GetFormFields( + const CFX_WideString& csFieldName) const { + return Field::GetFormFields(m_pDocument, csFieldName); } void Field::UpdateFormField(CPDFSDK_Document* pDocument, @@ -224,49 +216,29 @@ void Field::UpdateFormField(CPDFSDK_Document* pDocument, FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh) { - ASSERT(pDocument != NULL); - ASSERT(pFormField != NULL); - + std::vector<CPDFSDK_Widget*> widgets; CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - - CFX_PtrArray widgets; - pInterForm->GetWidgets(pFormField, widgets); + pInterForm->GetWidgets(pFormField, &widgets); if (bResetAP) { int nFieldType = pFormField->GetFieldType(); if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) { - for (int i = 0, sz = widgets.GetSize(); i < sz; i++) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i); - ASSERT(pWidget != NULL); - - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = pWidget->OnFormat(bFormated); - if (bFormated) - pWidget->ResetAppearance(sValue.c_str(), FALSE); - else - pWidget->ResetAppearance(NULL, FALSE); + for (CPDFSDK_Widget* pWidget : widgets) { + FX_BOOL bFormatted = FALSE; + CFX_WideString sValue = pWidget->OnFormat(bFormatted); + pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE); } } else { - for (int i = 0, sz = widgets.GetSize(); i < sz; i++) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i); - ASSERT(pWidget != NULL); - - pWidget->ResetAppearance(NULL, FALSE); + for (CPDFSDK_Widget* pWidget : widgets) { + pWidget->ResetAppearance(nullptr, FALSE); } } } if (bRefresh) { - for (int i = 0, sz = widgets.GetSize(); i < sz; i++) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i); - ASSERT(pWidget != NULL); - - CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); - CPDFSDK_Document* pDoc = pInterForm->GetDocument(); - // CReader_Page* pPage = pWidget->GetPage(); - ASSERT(pDoc != NULL); - pDoc->UpdateAllViews(NULL, pWidget); + for (CPDFSDK_Widget* pWidget : widgets) { + CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument(); + pDoc->UpdateAllViews(nullptr, pWidget); } } @@ -371,14 +343,11 @@ FX_BOOL Field::alignment(IJS_Context* cc, alignStr); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -430,12 +399,11 @@ FX_BOOL Field::borderStyle(IJS_Context* cc, strType); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; if (!pFormField) return FALSE; @@ -492,18 +460,14 @@ void Field::SetBorderStyle(CPDFSDK_Document* pDocument, else return; - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { if (nControlIndex < 0) { FX_BOOL bSet = FALSE; - for (int j = 0, jsz = pFormField->CountControls(); j < jsz; j++) { + for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { if (CPDFSDK_Widget* pWidget = - GetWidget(pDocument, pFormField->GetControl(j))) { + GetWidget(pDocument, pFormField->GetControl(i))) { if (pWidget->GetBorderStyle() != nBorderStyle) { pWidget->SetBorderStyle(nBorderStyle); bSet = TRUE; @@ -547,14 +511,11 @@ FX_BOOL Field::buttonAlignX(IJS_Context* cc, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -599,14 +560,11 @@ FX_BOOL Field::buttonAlignY(IJS_Context* cc, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -651,14 +609,11 @@ FX_BOOL Field::buttonFitBounds(IJS_Context* cc, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -699,14 +654,11 @@ FX_BOOL Field::buttonPosition(IJS_Context* cc, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -745,14 +697,11 @@ FX_BOOL Field::buttonScaleHow(IJS_Context* cc, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -796,14 +745,11 @@ FX_BOOL Field::buttonScaleWhen(IJS_Context* cc, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -858,17 +804,15 @@ FX_BOOL Field::calcOrderIndex(IJS_Context* cc, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && - pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) { return FALSE; + } CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm(); ASSERT(pRDInterForm != NULL); @@ -907,14 +851,11 @@ FX_BOOL Field::charLimit(IJS_Context* cc, Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -948,14 +889,11 @@ FX_BOOL Field::comb(IJS_Context* cc, Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -994,17 +932,15 @@ FX_BOOL Field::commitOnSelChange(IJS_Context* cc, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && - pFormField->GetFieldType() != FIELDTYPE_LISTBOX) + pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { return FALSE; + } if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE) vp << true; @@ -1056,29 +992,28 @@ FX_BOOL Field::currentValueIndices(IJS_Context* cc, m_nFormControlIndex, array); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && - pFormField->GetFieldType() != FIELDTYPE_LISTBOX) + pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { return FALSE; + } - if (pFormField->CountSelectedItems() == 1) + if (pFormField->CountSelectedItems() == 1) { vp << pFormField->GetSelectedIndex(0); - else if (pFormField->CountSelectedItems() > 1) { + } else if (pFormField->CountSelectedItems() > 1) { CJS_Array SelArray(pRuntime); for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { SelArray.SetElement( i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); } vp << SelArray; - } else + } else { vp << -1; + } } return TRUE; @@ -1090,13 +1025,9 @@ void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_DWordArray& array) { ASSERT(pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { int nFieldType = pFormField->GetFieldType(); if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) { FX_DWORD dwFieldFlags = pFormField->GetFieldFlags(); @@ -1120,18 +1051,7 @@ void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, FX_BOOL Field::defaultStyle(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT); return FALSE; - - if (vp.IsSetting()) { - if (!m_bCanSet) - return FALSE; - - ; - } else { - ; - } - return TRUE; } void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, @@ -1159,17 +1079,15 @@ FX_BOOL Field::defaultValue(IJS_Context* cc, WideStr); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON || - pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) + pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) { return FALSE; + } vp << pFormField->GetDefaultValue(); } @@ -1201,14 +1119,11 @@ FX_BOOL Field::doNotScroll(IJS_Context* cc, Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -1240,17 +1155,15 @@ FX_BOOL Field::doNotSpellCheck(IJS_Context* cc, bool bVP; vp >> bVP; } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD && - pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) + pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) { return FALSE; + } if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK) vp << true; @@ -1305,18 +1218,14 @@ FX_BOOL Field::display(IJS_Context* cc, Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; + ASSERT(pFormField); CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); if (!pWidget) @@ -1351,17 +1260,13 @@ void Field::SetDisplay(CPDFSDK_Document* pDocument, CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { if (nControlIndex < 0) { FX_BOOL bSet = FALSE; - for (int j = 0, jsz = pFormField->CountControls(); j < jsz; j++) { - CPDF_FormControl* pFormControl = pFormField->GetControl(j); + for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { + CPDF_FormControl* pFormControl = pFormField->GetControl(i); ASSERT(pFormControl != NULL); if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { @@ -1460,14 +1365,11 @@ FX_BOOL Field::editable(IJS_Context* cc, bool bVP; vp >> bVP; } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) return FALSE; @@ -1483,15 +1385,15 @@ FX_BOOL Field::editable(IJS_Context* cc, FX_BOOL Field::exportValues(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && - pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) + pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) { return FALSE; + } if (vp.IsSetting()) { if (!m_bCanSet) @@ -1530,12 +1432,11 @@ FX_BOOL Field::fileSelect(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -1559,9 +1460,8 @@ FX_BOOL Field::fillColor(IJS_Context* cc, CFX_WideString& sError) { CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); CJS_Array crArray(pRuntime); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; if (vp.IsSetting()) { @@ -1581,9 +1481,8 @@ FX_BOOL Field::fillColor(IJS_Context* cc, Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color); } } else { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; + ASSERT(pFormField); CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -1608,8 +1507,9 @@ FX_BOOL Field::fillColor(IJS_Context* cc, pFormControl->GetOriginalBackgroundColor(1), pFormControl->GetOriginalBackgroundColor(2), pFormControl->GetOriginalBackgroundColor(3)); - } else + } else { return FALSE; + } color::ConvertPWLColorToArray(color, crArray); vp << crArray; @@ -1643,18 +1543,14 @@ FX_BOOL Field::hidden(IJS_Context* cc, Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; + ASSERT(pFormField); CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); if (!pWidget) @@ -1662,9 +1558,9 @@ FX_BOOL Field::hidden(IJS_Context* cc, FX_DWORD dwFlags = pWidget->GetFlags(); - if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) { + if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) vp << true; - } else + else vp << false; } @@ -1680,18 +1576,14 @@ void Field::SetHidden(CPDFSDK_Document* pDocument, CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { if (nControlIndex < 0) { FX_BOOL bSet = FALSE; - for (int j = 0, jsz = pFormField->CountControls(); j < jsz; j++) { + for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { if (CPDFSDK_Widget* pWidget = - pInterForm->GetWidget(pFormField->GetControl(j))) { + pInterForm->GetWidget(pFormField->GetControl(i))) { FX_DWORD dwFlags = pWidget->GetFlags(); if (b) { @@ -1762,14 +1654,11 @@ FX_BOOL Field::highlight(IJS_Context* cc, strMode); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -1826,14 +1715,12 @@ FX_BOOL Field::lineWidth(IJS_Context* cc, iWidth); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; + ASSERT(pFormField); CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -1864,17 +1751,13 @@ void Field::SetLineWidth(CPDFSDK_Document* pDocument, CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { if (nControlIndex < 0) { FX_BOOL bSet = FALSE; - for (int j = 0, jsz = pFormField->CountControls(); j < jsz; j++) { - CPDF_FormControl* pFormControl = pFormField->GetControl(j); + for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { + CPDF_FormControl* pFormControl = pFormField->GetControl(i); ASSERT(pFormControl != NULL); if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { @@ -1920,14 +1803,11 @@ FX_BOOL Field::multiline(IJS_Context* cc, Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -1966,14 +1846,11 @@ FX_BOOL Field::multipleSelection(IJS_Context* cc, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) return FALSE; @@ -1999,9 +1876,8 @@ FX_BOOL Field::name(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; vp << m_FieldName; @@ -2015,15 +1891,15 @@ FX_BOOL Field::numItems(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && - pFormField->GetFieldType() != FIELDTYPE_LISTBOX) + pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { return FALSE; + } vp << (int32_t)pFormField->CountOptions(); return TRUE; @@ -2035,38 +1911,34 @@ FX_BOOL Field::page(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; if (!pFormField) return FALSE; - CFX_PtrArray widgetArray; - CPDFSDK_InterForm* pInterForm = - (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - pInterForm->GetWidgets(pFormField, widgetArray); + std::vector<CPDFSDK_Widget*> widgets; + m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets); - if (widgetArray.GetSize() > 0) { - CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); - CJS_Array PageArray(pRuntime); - for (int i = 0, sz = widgetArray.GetSize(); i < sz; i++) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i); - CPDFSDK_PageView* pPageView = pWidget->GetPageView(); - if (!pPageView) - return FALSE; + if (widgets.empty()) { + vp << (int32_t)-1; + return TRUE; + } - PageArray.SetElement( - i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); - } + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); + CJS_Array PageArray(pRuntime); + for (size_t i = 0; i < widgets.size(); ++i) { + CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); + if (!pPageView) + return FALSE; - vp << PageArray; - } else { - vp << (int32_t)-1; + PageArray.SetElement( + i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); } + vp << PageArray; return TRUE; } @@ -2088,14 +1960,11 @@ FX_BOOL Field::password(IJS_Context* cc, Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -2124,9 +1993,8 @@ FX_BOOL Field::print(IJS_Context* cc, (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; if (vp.IsSetting()) { @@ -2136,15 +2004,12 @@ FX_BOOL Field::print(IJS_Context* cc, bool bVP; vp >> bVP; - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + for (CPDF_FormField* pFormField : FieldArray) { if (m_nFormControlIndex < 0) { FX_BOOL bSet = FALSE; - for (int j = 0, jsz = pFormField->CountControls(); j < jsz; j++) { + for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { if (CPDFSDK_Widget* pWidget = - pInterForm->GetWidget(pFormField->GetControl(j))) { + pInterForm->GetWidget(pFormField->GetControl(i))) { FX_DWORD dwFlags = pWidget->GetFlags(); if (bVP) dwFlags |= ANNOTFLAG_PRINT; @@ -2183,9 +2048,7 @@ FX_BOOL Field::print(IJS_Context* cc, } } } else { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); if (!pWidget) @@ -2205,9 +2068,8 @@ FX_BOOL Field::radiosInUnison(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; if (vp.IsSetting()) { @@ -2218,9 +2080,7 @@ FX_BOOL Field::radiosInUnison(IJS_Context* cc, vp >> bVP; } else { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) return FALSE; @@ -2238,9 +2098,8 @@ FX_BOOL Field::readonly(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; if (vp.IsSetting()) { @@ -2251,9 +2110,7 @@ FX_BOOL Field::readonly(IJS_Context* cc, vp >> bVP; } else { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY) vp << true; else @@ -2298,12 +2155,11 @@ FX_BOOL Field::rect(IJS_Context* cc, Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); CPDFSDK_Widget* pWidget = @@ -2336,16 +2192,12 @@ void Field::SetRect(CPDFSDK_Document* pDocument, CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { if (nControlIndex < 0) { FX_BOOL bSet = FALSE; - for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { + for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { CPDF_FormControl* pFormControl = pFormField->GetControl(i); ASSERT(pFormControl != NULL); @@ -2353,11 +2205,6 @@ void Field::SetRect(CPDFSDK_Document* pDocument, CPDF_Rect crRect = rect; CPDF_Page* pPDFPage = pWidget->GetPDFPage(); - ASSERT(pPDFPage != NULL); - - // CPDF_Page* pPDFPage = pPage->GetPage(); - // ASSERT(pPDFPage != NULL); - crRect.Intersect(pPDFPage->GetPageBBox()); if (!crRect.IsEmpty()) { @@ -2408,9 +2255,8 @@ FX_BOOL Field::required(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; if (vp.IsSetting()) { @@ -2421,9 +2267,7 @@ FX_BOOL Field::required(IJS_Context* cc, vp >> bVP; } else { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) return FALSE; @@ -2454,14 +2298,11 @@ FX_BOOL Field::richText(IJS_Context* cc, Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) return FALSE; @@ -2485,14 +2326,6 @@ FX_BOOL Field::richValue(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { return TRUE; - if (vp.IsSetting()) { - if (!m_bCanSet) - return FALSE; - ; - } else { - ; - } - return TRUE; } void Field::SetRichValue(CPDFSDK_Document* pDocument, @@ -2519,14 +2352,11 @@ FX_BOOL Field::rotation(IJS_Context* cc, Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -2569,12 +2399,11 @@ FX_BOOL Field::strokeColor(IJS_Context* cc, color); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -2598,8 +2427,9 @@ FX_BOOL Field::strokeColor(IJS_Context* cc, pFormControl->GetOriginalBorderColor(1), pFormControl->GetOriginalBorderColor(2), pFormControl->GetOriginalBorderColor(3)); - } else + } else { return FALSE; + } color::ConvertPWLColorToArray(color, crArray); vp << crArray; @@ -2633,17 +2463,15 @@ FX_BOOL Field::style(IJS_Context* cc, csBCaption); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON && - pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) + pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) { return FALSE; + } CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) @@ -2715,12 +2543,11 @@ FX_BOOL Field::textColor(IJS_Context* cc, Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -2773,14 +2600,12 @@ FX_BOOL Field::textFont(IJS_Context* cc, csFontName); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; + ASSERT(pFormField); CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -2795,8 +2620,9 @@ FX_BOOL Field::textFont(IJS_Context* cc, return FALSE; vp << pFont->GetBaseFont(); - } else + } else { return FALSE; + } } return TRUE; @@ -2827,14 +2653,12 @@ FX_BOOL Field::textSize(IJS_Context* cc, Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; + ASSERT(pFormField); CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); if (!pFormControl) return FALSE; @@ -2867,14 +2691,11 @@ FX_BOOL Field::type(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; switch (pFormField->GetFieldType()) { case FIELDTYPE_UNKNOWN: vp << L"unknown"; @@ -2926,14 +2747,11 @@ FX_BOOL Field::userName(IJS_Context* cc, Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; vp << (CFX_WideString)pFormField->GetAlternateName(); } @@ -2978,12 +2796,11 @@ FX_BOOL Field::value(IJS_Context* cc, Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray); } } else { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; switch (pFormField->GetFieldType()) { case FIELDTYPE_PUSHBUTTON: return FALSE; @@ -2999,8 +2816,9 @@ FX_BOOL Field::value(IJS_Context* cc, vp << dRet; else vp << dRet; - } else + } else { vp << swValue; + } } break; case FIELDTYPE_LISTBOX: { if (pFormField->CountSelectedItems() > 1) { @@ -3026,32 +2844,30 @@ FX_BOOL Field::value(IJS_Context* cc, vp << dRet; else vp << dRet; - } else + } else { vp << swValue; + } } } break; case FIELDTYPE_CHECKBOX: case FIELDTYPE_RADIOBUTTON: { FX_BOOL bFind = FALSE; for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { - if (pFormField->GetControl(i)->IsChecked()) { - CFX_WideString swValue = - pFormField->GetControl(i)->GetExportValue(); - double dRet; - FX_BOOL bDot; - if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, - bDot)) { - if (bDot) - vp << dRet; - else - vp << dRet; - } else - vp << swValue; - - bFind = TRUE; - break; - } else + if (!pFormField->GetControl(i)->IsChecked()) continue; + + CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue(); + double dRet; + FX_BOOL bDotDummy; + if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, + bDotDummy)) { + vp << dRet; + } else { + vp << swValue; + } + + bFind = TRUE; + break; } if (!bFind) vp << L"Off"; @@ -3074,13 +2890,10 @@ void Field::SetValue(CPDFSDK_Document* pDocument, if (strArray.GetSize() < 1) return; - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); - - for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); + std::vector<CPDF_FormField*> FieldArray = + GetFormFields(pDocument, swFieldName); + for (CPDF_FormField* pFormField : FieldArray) { if (pFormField->GetFullName().Compare(swFieldName) != 0) continue; @@ -3136,14 +2949,11 @@ FX_BOOL Field::valueAsString(IJS_Context* cc, if (!vp.IsGetting()) return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) return FALSE; @@ -3161,14 +2971,16 @@ FX_BOOL Field::valueAsString(IJS_Context* cc, if (pFormField->GetControl(i)->IsChecked()) { vp << pFormField->GetControl(i)->GetExportValue().c_str(); break; - } else + } else { vp << L"Off"; + } } } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1)) { vp << L""; - } else + } else { vp << pFormField->GetValue().c_str(); + } return TRUE; } @@ -3182,17 +2994,12 @@ FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); - ASSERT(pApp != NULL); - if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) && (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) { CFX_WideString wsFileName = pApp->JS_fieldBrowse(); @@ -3200,10 +3007,9 @@ FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc, pFormField->SetValue(wsFileName); UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE); } - } else - return FALSE; - - return TRUE; + return TRUE; + } + return FALSE; } FX_BOOL Field::buttonGetCaption(IJS_Context* cc, @@ -3217,14 +3023,11 @@ FX_BOOL Field::buttonGetCaption(IJS_Context* cc, if (iSize >= 1) nface = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -3244,8 +3047,6 @@ FX_BOOL Field::buttonGetCaption(IJS_Context* cc, return TRUE; } -//#pragma warning(disable: 4800) - FX_BOOL Field::buttonGetIcon(IJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, @@ -3257,12 +3058,11 @@ FX_BOOL Field::buttonGetIcon(IJS_Context* cc, if (iSize >= 1) nface = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) return FALSE; @@ -3299,44 +3099,6 @@ FX_BOOL Field::buttonImportIcon(IJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { -#if 0 - ASSERT(m_pDocument != NULL); - - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; - - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - if (!pFormField)return FALSE; - - CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); - ASSERT(pEnv); - - CFX_WideString sIconFileName = pEnv->JS_fieldBrowse(); - if (sIconFileName.IsEmpty()) - { - vRet = 1; - return TRUE; - } - - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - - CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName); - if (!pStream) - { - vRet = -1; - return TRUE; - } - - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; - - pFormControl->SetNormalIcon(pStream); - UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE); - - vRet = 0; -#endif // 0 return TRUE; } @@ -3373,14 +3135,11 @@ FX_BOOL Field::checkThisBox(IJS_Context* cc, if (iSize >= 2) bCheckit = params[1].ToBool(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) return FALSE; @@ -3417,23 +3176,17 @@ FX_BOOL Field::defaultIsChecked(IJS_Context* cc, int nWidget = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (nWidget < 0 || nWidget >= pFormField->CountControls()) { vRet = FALSE; return FALSE; } - if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) || - (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) { - vRet = TRUE; - } else - vRet = FALSE; + vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || + pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON; return TRUE; } @@ -3458,25 +3211,19 @@ FX_BOOL Field::getArray(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; CGW_ArrayTemplate<CFX_WideString*> swSort; - for (int i = 0, sz = FieldArray.GetSize(); i < sz; i++) { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); - ASSERT(pFormField != NULL); - + for (CPDF_FormField* pFormField : FieldArray) swSort.Add(new CFX_WideString(pFormField->GetFullName())); - } swSort.Sort(JS_COMPARESTRING); CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + ASSERT(pRuntime); CJS_Array FormFieldArray(pRuntime); for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) { @@ -3515,14 +3262,11 @@ FX_BOOL Field::getItemAt(IJS_Context* cc, if (iSize >= 2) bExport = params[1].ToBool(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) || (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) { if (nIdx == -1 || nIdx > pFormField->CountOptions()) @@ -3533,10 +3277,12 @@ FX_BOOL Field::getItemAt(IJS_Context* cc, vRet = pFormField->GetOptionLabel(nIdx).c_str(); else vRet = strval.c_str(); - } else + } else { vRet = pFormField->GetOptionLabel(nIdx).c_str(); - } else + } + } else { return FALSE; + } return TRUE; } @@ -3565,14 +3311,11 @@ FX_BOOL Field::isBoxChecked(IJS_Context* cc, if (params.size() >= 1) nIndex = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (nIndex < 0 || nIndex >= pFormField->CountControls()) { vRet = FALSE; return FALSE; @@ -3584,8 +3327,9 @@ FX_BOOL Field::isBoxChecked(IJS_Context* cc, vRet = TRUE; else vRet = FALSE; - } else + } else { vRet = FALSE; + } return TRUE; } @@ -3600,14 +3344,11 @@ FX_BOOL Field::isDefaultChecked(IJS_Context* cc, if (params.size() >= 1) nIndex = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; if (nIndex < 0 || nIndex >= pFormField->CountControls()) { vRet = FALSE; return FALSE; @@ -3618,8 +3359,9 @@ FX_BOOL Field::isDefaultChecked(IJS_Context* cc, vRet = TRUE; else vRet = FALSE; - } else + } else { vRet = FALSE; + } return TRUE; } @@ -3637,16 +3379,12 @@ FX_BOOL Field::setFocus(IJS_Context* cc, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) + std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); + if (FieldArray.empty()) return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); - + CPDF_FormField* pFormField = FieldArray[0]; int32_t nCount = pFormField->CountControls(); - if (nCount < 1) return FALSE; diff --git a/fpdfsdk/src/javascript/Field.h b/fpdfsdk/src/javascript/Field.h index 21ae04c960..d0ee490e80 100644 --- a/fpdfsdk/src/javascript/Field.h +++ b/fpdfsdk/src/javascript/Field.h @@ -89,7 +89,7 @@ struct CJS_DelayData { class Field : public CJS_EmbedObj { public: - Field(CJS_Object* pJSObject); + explicit Field(CJS_Object* pJSObject); ~Field() override; FX_BOOL alignment(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); @@ -292,7 +292,6 @@ class Field : public CJS_EmbedObj { CJS_Value& vRet, CFX_WideString& sError); - public: static void SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, @@ -432,14 +431,12 @@ class Field : public CJS_EmbedObj { int nControlIndex, const CJS_WideStringArray& strArray); - public: static void AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType, const CFX_WideString& sName, const CPDF_Rect& rcCoords); - public: static void UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, FX_BOOL bChangeMark, @@ -453,13 +450,12 @@ class Field : public CJS_EmbedObj { static CPDFSDK_Widget* GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl); - static void GetFormFields(CPDFSDK_Document* pDocument, - const CFX_WideString& csFieldName, - CFX_PtrArray& FieldsArray); + static std::vector<CPDF_FormField*> GetFormFields( + CPDFSDK_Document* pDocument, + const CFX_WideString& csFieldName); static void DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData); - public: FX_BOOL AttachField(Document* pDocument, const CFX_WideString& csFieldName); void SetDelay(FX_BOOL bDelay); void SetIsolate(v8::Isolate* isolate) { m_isolate = isolate; } @@ -468,8 +464,8 @@ class Field : public CJS_EmbedObj { void ParseFieldName(const std::wstring& strFieldNameParsed, std::wstring& strFieldName, int& iControlNo); - void GetFormFields(const CFX_WideString& csFieldName, - CFX_PtrArray& FieldsArray); + std::vector<CPDF_FormField*> GetFormFields( + const CFX_WideString& csFieldName) const; CPDF_FormControl* GetSmartFieldControl(CPDF_FormField* pFormField); FX_BOOL ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel); @@ -498,7 +494,7 @@ class Field : public CJS_EmbedObj { class CJS_Field : public CJS_Object { public: - CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} + explicit CJS_Field(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} ~CJS_Field(void) override {} void InitInstance(IJS_Runtime* pIRuntime) override; diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp index 9be02ccb1e..2ff515d0ab 100644 --- a/fpdfsdk/src/jsapi/fxjs_v8.cpp +++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp @@ -30,24 +30,24 @@ static v8::Global<v8::ObjectTemplate>* g_DefaultGlobalObjectTemplate = nullptr; class CFXJS_PerObjectData { public: - CFXJS_PerObjectData(int nObjDefID) + explicit CFXJS_PerObjectData(int nObjDefID) : m_ObjDefID(nObjDefID), m_pPrivate(nullptr) {} - int m_ObjDefID; + const int m_ObjDefID; void* m_pPrivate; }; class CFXJS_ObjDefinition { public: static int MaxID(v8::Isolate* pIsolate) { - return static_cast<int>( - FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.GetSize()); + return FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.size(); } + static CFXJS_ObjDefinition* ForID(v8::Isolate* pIsolate, int id) { // Note: GetAt() halts if out-of-range even in release builds. - return static_cast<CFXJS_ObjDefinition*>( - FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.GetAt(id)); + return FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray[id]; } + CFXJS_ObjDefinition(v8::Isolate* isolate, const wchar_t* sObjName, FXJSOBJTYPE eObjType, @@ -71,8 +71,8 @@ class CFXJS_ObjDefinition { int AssignID() { FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_pIsolate); - pData->m_ObjectDefnArray.Add(this); - return pData->m_ObjectDefnArray.GetSize() - 1; + pData->m_ObjectDefnArray.push_back(this); + return pData->m_ObjectDefnArray.size() - 1; } v8::Local<v8::ObjectTemplate> GetInstanceTemplate() { @@ -558,8 +558,7 @@ v8::Local<v8::Array> FXJS_GetObjectElementNames(v8::Isolate* pIsolate, void FXJS_PutObjectString(v8::Isolate* pIsolate, v8::Local<v8::Object> pObj, const wchar_t* PropertyName, - const wchar_t* sValue) // VT_string -{ + const wchar_t* sValue) { if (pObj.IsEmpty()) return; pObj->Set(pIsolate->GetCurrentContext(), |