nsString text(" ");
NS_IMETHODIMP nsNativeSelectControlFrame::RemoveOption(PRInt32 aIndex){    // Grab the content model information (merge with postcreatewidget code?)    nsIDOMHTMLCollection* options = GetOptions();    if (!options) return NS_ERROR_UNEXPECTED;    // Save the cache data structure    PRUint32 saveNumOptions = mNumOptions;    PRBool* saveOptionSelected = mOptionSelected;    PRBool selected = PR_FALSE;    nsString text(" ");    // Grab the widget (we need to update it)    nsIListWidget* listWidget;    nsresult result = mWidget->QueryInterface(kListWidgetIID, (void **) &listWidget);    if ((NS_FAILED(result)) || (nsnull == listWidget)) {      return NS_ERROR_UNEXPECTED;    }      mNumOptions--;      if (mNumOptions) {        mOptionSelected = new PRBool[mNumOptions];        if (!mOptionSelected) return NS_ERROR_OUT_OF_MEMORY;      } else {        mOptionSelected = nsnull;      }      // If we got the index, remove just that one option, like this:      if (aIndex >= 0) {        // Copy saved local cache into new local cache        for (PRInt32 i=0, j=0; j < mNumOptions; i++,j++) {          if (i == aIndex) i++; // At the point of deletion          mOptionSelected[j]=saveOptionSelected[i];        }        // Update widget        listWidget->RemoveItemAt(aIndex);      // No index, so we'll have to remove all options and recreate. (Performance hit)      // We also loose the status of what has been selected.      } else {        // Remove all stale options        PRInt32 i;        for (i=saveNumOptions; i>=0; i--) {          listWidget->RemoveItemAt(i);        }        // Add all the options back in        for (i=0; i<mNumOptions; i++) {          // Get the default (XXXincorrect) selected value and text of the option          nsIDOMNode* node = nsnull;          options->Item(i, &node);          if (node) {            nsIDOMHTMLOptionElement* option = nsnull;            result = node->QueryInterface(kIDOMHTMLOptionElementIID, (void**)&option);            if ((NS_OK == result) && option) {              option->GetDefaultSelected(&selected); // Should be sel, not defsel :(              mOptionSelected[i]=selected;              // XXX need to compress whitespace              if (NS_CONTENT_ATTR_HAS_VALUE != option->GetText(text)) {                text = " "; // needed?              }              NS_RELEASE(option);            } else {              mOptionSelected[i]=PR_FALSE; // Couldn't get selected val from content!              text = " ";            }            NS_RELEASE(node);          } else {            mOptionSelected[i]=PR_FALSE; // Couldn't get selected val from content!            text = " ";          }          listWidget->AddItemAt(text, i);        }      }    // Select options as needed (this is needed for Windows at least)    // Note, as mentioned above, we can't restore selection if option is    // replaced - no index is reported back to us - use DefaultSelected instead    listWidget->Deselect();    PRInt32 selectedIndex = -1;    for (PRInt32 i=0; i < mNumOptions; i++) {      GetOptionSelected(i, &selected);      if (selected) {        listWidget->SelectItem(i);        selectedIndex = i;      }    }    if (mIsComboBox && (mNumOptions > 0) && (selectedIndex == -1)) {      listWidget->SelectItem(0);      SetOptionSelected(0, PR_TRUE);    }    NS_RELEASE(options);    NS_RELEASE(listWidget);    if (saveOptionSelected)      delete [] saveOptionSelected;    return NS_OK;}