FX_BOOL CPDF_FormField::IsItemSelected(int index) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) { return FALSE; } if (IsOptionSelected(index)) { return TRUE; } CFX_WideString opt_value = GetOptionValue(index); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue == NULL) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (pValue == NULL) { return FALSE; } } if (pValue->GetType() == PDFOBJ_STRING) { if (pValue->GetUnicodeText() == opt_value) { return TRUE; } return FALSE; } if (pValue->GetType() == PDFOBJ_NUMBER) { if (pValue->GetString().IsEmpty()) { return FALSE; } if (pValue->GetInteger() == index) { return TRUE; } return FALSE; } if (pValue->GetType() != PDFOBJ_ARRAY) { return FALSE; } CPDF_Array* pArray = (CPDF_Array*)pValue; int iPos = -1; for (int j = 0; j < CountSelectedOptions(); j ++) { if (GetSelectedOptionIndex(j) == index) { iPos = j; break; } } for (FX_DWORD i = 0; i < pArray->GetCount(); i ++) if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i == iPos) { return TRUE; } return FALSE; }
FX_BOOL CPDF_FormField::IsItemSelected(int index) const { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) { return FALSE; } if (IsOptionSelected(index)) { return TRUE; } CFX_WideString opt_value = GetOptionValue(index); CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (!pValue) { pValue = FPDF_GetFieldAttr(m_pDict, "I"); if (!pValue) { return FALSE; } } if (pValue->IsString()) return pValue->GetUnicodeText() == opt_value; if (pValue->IsNumber()) { if (pValue->GetString().IsEmpty()) return FALSE; return (pValue->GetInteger() == index); } CPDF_Array* pArray = pValue->AsArray(); if (!pArray) return FALSE; int iPos = -1; for (int j = 0; j < CountSelectedOptions(); j++) { if (GetSelectedOptionIndex(j) == index) { iPos = j; break; } } for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++) if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && i == iPos) { return TRUE; } return FALSE; }