changes enumerator to do the right thing

This commit is contained in:
mjudge%netscape.com 1998-12-01 17:58:10 +00:00
parent 7135c7af4a
commit 5969fa01ca
2 changed files with 92 additions and 11 deletions

View File

@ -288,14 +288,91 @@ NS_IMPL_ISUPPORTS(nsRadioGroup::Enumerator, NS_IENUMERATOR_IID);
// Get enumeration next element. Return null at the end
//
//-------------------------------------------------------------------------
nsISupports* nsRadioGroup::Enumerator::Next()
{
if (mCurrentPosition < mArraySize && mChildrens[mCurrentPosition]) {
NS_ADDREF(mChildrens[mCurrentPosition]);
return mChildrens[mCurrentPosition++];
}
return NULL;
nsresult
nsRadioGroup::Enumerator::Next()
{
if (mCurrentPosition < (mArraySize -1) )
mCurrentPosition ++;
else
return NS_ERROR_FAILURE;
return NS_OK
}
nsresult
nsRadioGroup::Enumerator::Prev()
{
if (mCurrentPosition > 0 )
mCurrentPosition --;
else
return NS_ERROR_FAILURE;
return NS_OK
}
nsresult
nsRadioGroup::Enumerator::CurrentItem(nsISupports **aItem)
{
if (!aItem)
return NS_ERROR_NULL_POINTER;
if (mCurrentPosition >= 0 && mCurrentPosition < mArraySize && mChildrens[mCurrentPosition]) {
NS_ADDREF(mChildrens[mCurrentPosition]);
*aItem = mChildrens[mCurrentPosition];
}
else
return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
nsRadioGroup::Enumerator::First()
{
if (mArraySize && mChildrens[0]) {
mCurrentPosition = 0;
return NS_OK;
}
else
return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
nsRadioGroup::Enumerator::Last()
{
if (mArraySize && mChildrens[0]) {
mCurrentPosition = mArraySize -1;
return NS_OK;
}
else
return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
nsRadioGroup::Enumerator::IsDone(PRBool *aDone)
{
if (!aDone)
return NS_ERROR_NULL_POINTER;
if ((mCurrentPosition == (mArraySize -1)) || mArraySize <= 0 ){ //empty lists always return done
*aDone = PR_TRUE;
}
else
*aDone = PR_FALSE;
return NS_OK;
}

View File

@ -68,10 +68,14 @@ protected:
NS_DECL_ISUPPORTS
Enumerator();
~Enumerator();
NS_IMETHOD_(nsISupports*) Next();
NS_IMETHOD_(void) Reset();
virtual ~Enumerator();
virtual nsresult First();
virtual nsresult Last();
virtual nsresult Next();
virtual nsresult Prev();
virtual nsresult CurrentItem(nsISupports **aItem);
virtual nsresult IsDone(PRBool *aDone);
void Append(nsIRadioButton* aWidget);
void Remove(nsIRadioButton* aWidget);