} else {  for (PRUint32 i=0; i < mNumOptions; i++) SetOptionSelected(i, PR_FALSE); SetOptionSelected(selectedIndex, PR_TRUE);
for (PRUint32 i=0; i < mNumOptions; i++) SetOptionSelected(i, PR_FALSE); SetOptionSelected(selectedIndex, PR_TRUE);   nsIListWidget* listWidget; nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); if ((NS_OK == result) && (nsnull != listWidget)) { listWidget->Deselect(); listWidget->SelectItem(selectedIndex); NS_RELEASE(listWidget); } } else if (nsHTMLAtoms::option == aName) { nsString aValCopy(aValue); aValCopy.Trim("ar",PR_TRUE,PR_FALSE); PRInt32 error = 0; PRInt32 actionIndex = aValCopy.ToInteger(&error, 10); if (error) return NS_ERROR_INVALID_ARG;   nsIDOMHTMLCollection* options = GetOptions(); if (!options) return NS_ERROR_UNEXPECTED;   PRUint32 saveNumOptions = mNumOptions; PRBool* saveOptionSelected = mOptionSelected; PRBool selected = PR_FALSE; nsString text(" ");   nsIListWidget* listWidget; nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); if ((NS_FAILED(result)) || (nsnull == listWidget)) { return NS_ERROR_UNEXPECTED; }  if (!aValue.Find("a")) { mNumOptions++; mOptionSelected = new PRBool[mNumOptions]; if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY;   for (PRUint32 i=0, j=0; j < mNumOptions; i++,j++) { if (i == actionIndex) {   nsIDOMNode* node = nsnull; options->Item(i, &node); if (node) { nsIDOMHTMLOptionElement* option = nsnull; nsresult result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option); if ((NS_OK == result) && option) { option->GetDefaultSelected(&selected); mOptionSelected[j]=selected;   if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { text = " "; } NS_RELEASE(option); } else { mOptionSelected[j]=PR_FALSE; } NS_RELEASE(node); } else { mOptionSelected[j]=PR_FALSE; } j++; }   if (j < mNumOptions) { mOptionSelected[j]=saveOptionSelected[i]; } }
NS_IMETHODIMP nsSelectControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue){  if (nsHTMLAtoms::selected == aName) {    return NS_ERROR_INVALID_ARG; // Selected is readonly according to spec.  } else if (nsHTMLAtoms::selectedindex == aName) {    PRInt32 error = 0;    PRInt32 selectedIndex = aValue.ToInteger(&error, 10); // Get index from aValue    if (error) {      return NS_ERROR_INVALID_ARG; // Couldn't convert to integer    } else {      // Update local cache of selected values      for (PRUint32 i=0; i < mNumOptions; i++)        SetOptionSelected(i, PR_FALSE);      SetOptionSelected(selectedIndex, PR_TRUE);      // Update widget      nsIListWidget* listWidget;      nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget);      if ((NS_OK == result) && (nsnull != listWidget)) {        listWidget->Deselect();        listWidget->SelectItem(selectedIndex);        NS_RELEASE(listWidget);      }    }  } else {    return nsFormControlFrame::SetProperty(aName, aValue);  }  return NS_OK;}