summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc/doc_formfield.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-12-18 17:05:11 -0800
committerLei Zhang <thestig@chromium.org>2015-12-18 17:05:11 -0800
commit4880d1a168729d42be736293fb93b514802e4f12 (patch)
tree9cfe5aa73113301487dce8bcef5139fb7295536a /core/src/fpdfdoc/doc_formfield.cpp
parentaedd4555ec1a80121f176586cb72180337e4ccd8 (diff)
downloadpdfium-4880d1a168729d42be736293fb93b514802e4f12.tar.xz
Merge to XFA: Get rid of a few CPDF_Object Create() methods and just use new instead.
R=ochang@chromium.org Review URL: https://codereview.chromium.org/1540693002 . (cherry picked from commit d866ab0b44a571c884fdd8ba5a5319adaf607559) Review URL: https://codereview.chromium.org/1541563002 .
Diffstat (limited to 'core/src/fpdfdoc/doc_formfield.cpp')
-rw-r--r--core/src/fpdfdoc/doc_formfield.cpp48
1 files changed, 16 insertions, 32 deletions
diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp
index c6428157e5..b62f8ba0b1 100644
--- a/core/src/fpdfdoc/doc_formfield.cpp
+++ b/core/src/fpdfdoc/doc_formfield.cpp
@@ -571,7 +571,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
m_pDict->RemoveAt("V");
}
} else if (pValue->IsArray()) {
- CPDF_Array* pArray = CPDF_Array::Create();
+ CPDF_Array* pArray = new CPDF_Array;
int iCount = CountOptions();
for (int i = 0; i < iCount; i++) {
if (i != index) {
@@ -598,13 +598,10 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
if (!(m_Flags & FORMLIST_MULTISELECT)) {
m_pDict->SetAtString("V", PDF_EncodeText(opt_value));
} else {
- CPDF_Array* pArray = CPDF_Array::Create();
- if (!pArray) {
- return FALSE;
- }
- FX_BOOL bSelected;
+ CPDF_Array* pArray = new CPDF_Array;
int iCount = CountOptions();
for (int i = 0; i < iCount; i++) {
+ FX_BOOL bSelected;
if (i != index) {
bSelected = IsItemSelected(i);
} else {
@@ -619,10 +616,7 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index,
}
} else if (m_Type == ComboBox) {
m_pDict->SetAtString("V", PDF_EncodeText(opt_value));
- CPDF_Array* pI = CPDF_Array::Create();
- if (!pI) {
- return FALSE;
- }
+ CPDF_Array* pI = new CPDF_Array;
pI->AddInteger(index);
m_pDict->SetAt("I", pI);
}
@@ -740,7 +734,7 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
if (csOptLabel.IsEmpty())
return -1;
- if (bNotify && m_pForm->m_pFormNotify != NULL) {
+ if (bNotify && m_pForm->m_pFormNotify) {
int iRet = 0;
if (GetType() == ListBox)
iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel);
@@ -751,27 +745,23 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
}
CFX_ByteString csStr = PDF_EncodeText(csOptLabel, csOptLabel.GetLength());
- CPDF_Array* pOpt = NULL;
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
- if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
- pOpt = CPDF_Array::Create();
- if (pOpt == NULL)
- return -1;
+ CPDF_Array* pOpt = ToArray(pValue);
+ if (!pOpt) {
+ pOpt = new CPDF_Array;
m_pDict->SetAt("Opt", pOpt);
- } else
- pOpt = (CPDF_Array*)pValue;
+ }
+
int iCount = (int)pOpt->GetCount();
if (index < 0 || index >= iCount) {
pOpt->AddString(csStr);
index = iCount;
} else {
- CPDF_String* pString = CPDF_String::Create(csStr);
- if (pString == NULL)
- return -1;
+ CPDF_String* pString = new CPDF_String(csStr, FALSE);
pOpt->InsertAt(index, pString);
}
- if (bNotify && m_pForm->m_pFormNotify != NULL) {
+ if (bNotify && m_pForm->m_pFormNotify) {
if (GetType() == ListBox)
m_pForm->m_pFormNotify->AfterSelectionChange(this);
if (GetType() == ComboBox)
@@ -781,7 +771,7 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
return index;
}
FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) {
- if (bNotify && m_pForm->m_pFormNotify != NULL) {
+ if (bNotify && m_pForm->m_pFormNotify) {
int iRet = 0;
CFX_WideString csValue;
int iIndex = GetSelectedIndex(0);
@@ -801,7 +791,7 @@ FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) {
m_pDict->RemoveAt("I");
m_pDict->RemoveAt("TI");
- if (bNotify && m_pForm->m_pFormNotify != NULL) {
+ if (bNotify && m_pForm->m_pFormNotify) {
if (GetType() == ListBox)
m_pForm->m_pFormNotify->AfterSelectionChange(this);
if (GetType() == ComboBox)
@@ -985,10 +975,7 @@ FX_BOOL CPDF_FormField::SelectOption(int iOptIndex,
if (!bSelected) {
return TRUE;
}
- pArray = CPDF_Array::Create();
- if (!pArray) {
- return FALSE;
- }
+ pArray = new CPDF_Array;
m_pDict->SetAt("I", pArray);
}
FX_BOOL bReturn = FALSE;
@@ -1031,10 +1018,7 @@ FX_BOOL CPDF_FormField::SelectOption(int iOptIndex,
return FALSE;
}
}
- CPDF_Number* pNum = CPDF_Number::Create(iOptIndex);
- if (!pNum) {
- return FALSE;
- }
+ CPDF_Number* pNum = new CPDF_Number(iOptIndex);
pArray->InsertAt(i, pNum);
bReturn = TRUE;
break;