nsIListWidget* listWidget; nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget); if ((NS_OK == result) && (nsnull != listWidget)) { listWidget->Deselect(); listWidget->SelectItem(selectedIndex); NS_RELEASE(listWidget);
listWidget->AddItemAt(text, actionIndex); } else { mNumOptions--; if (mNumOptions) { mOptionSelected = new PRBool[mNumOptions]; if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY; } else { mOptionSelected = nsnull; }  if (actionIndex >= 0) {  for (PRUint32 i=0, j=0; j < mNumOptions; i++,j++) { if (i == actionIndex) i++; mOptionSelected[j]=saveOptionSelected[i]; }   listWidget->RemoveItemAt(actionIndex);    } else {  PRInt32 i; for (i=saveNumOptions; i>=0; i--) { listWidget->RemoveItemAt(i); }   PRBool selected = PR_FALSE; nsString text(" "); for (i=0; i<mNumOptions; i++) {  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[i]=selected;   if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) { text = " "; } NS_RELEASE(option); } else { mOptionSelected[i]=PR_FALSE; text = " "; } NS_RELEASE(node); } else { mOptionSelected[i]=PR_FALSE; text = " "; } listWidget->AddItemAt(text, 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;}