Adjust current index of combobox when options are added or removed. b=286170 r+sr=bzbarsky a=asa

git-svn-id: svn://10.0.0.236/trunk@174900 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mats.palmgren%bredband.net
2005-06-20 23:26:35 +00:00
parent a0fa232c8c
commit 1542a75ce7
2 changed files with 29 additions and 18 deletions

View File

@@ -1898,10 +1898,11 @@ nsComboboxControlFrame::DoneAddingChildren(PRBool aIsDone)
NS_IMETHODIMP
nsComboboxControlFrame::AddOption(nsPresContext* aPresContext, PRInt32 aIndex)
{
#ifdef DO_REFLOW_DEBUGXX
printf("*********AddOption: %d\n", aIndex);
#endif
nsListControlFrame * lcf = NS_STATIC_CAST(nsListControlFrame*, mDropdownFrame);
if (aIndex <= mDisplayedIndex) {
++mDisplayedIndex;
}
nsListControlFrame* lcf = NS_STATIC_CAST(nsListControlFrame*, mDropdownFrame);
return lcf->AddOption(aPresContext, aIndex);
}
@@ -1909,10 +1910,18 @@ nsComboboxControlFrame::AddOption(nsPresContext* aPresContext, PRInt32 aIndex)
NS_IMETHODIMP
nsComboboxControlFrame::RemoveOption(nsPresContext* aPresContext, PRInt32 aIndex)
{
// If we removed the last option, we need to blank things out
PRInt32 len;
mListControlFrame->GetNumberOfOptions(&len);
if (len == 0) {
if (len > 0) {
if (aIndex < mDisplayedIndex) {
--mDisplayedIndex;
} else if (aIndex == mDisplayedIndex) {
mDisplayedIndex = 0; // IE6 compat
RedisplayText(mDisplayedIndex);
}
}
else {
// If we removed the last option, we need to blank things out
RedisplayText(-1);
}