Use nsCOMArray instead of nsISupportsArray. Also kills off tabs. Bug 227491,

r=caillon, sr=dbaron
This commit is contained in:
bzbarsky%mit.edu 2004-01-05 23:28:41 +00:00
parent d1d245f091
commit e5cedca9d0
4 changed files with 113 additions and 137 deletions

View File

@ -604,14 +604,10 @@ NS_IMETHODIMP nsWidget::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
gtk_widget_set_usize(mWidget, aWidth, aHeight);
ResetInternalVisibility();
PRUint32 childCount, index;
if (NS_SUCCEEDED(mChildren->Count(&childCount))) {
PRInt32 childCount = mChildren.Count();
PRInt32 index;
for (index = 0; index < childCount; index++) {
nsCOMPtr<nsIWidget> childWidget;
if (NS_SUCCEEDED(mChildren->QueryElementAt(index, NS_GET_IID(nsIWidget), (void**)getter_AddRefs(childWidget)))) {
NS_STATIC_CAST(nsWidget*, NS_STATIC_CAST(nsIWidget*, childWidget.get()))->ResetInternalVisibility();
}
}
NS_STATIC_CAST(nsWidget*, mChildren[index])->ResetInternalVisibility();
}
return NS_OK;

View File

@ -2769,14 +2769,10 @@ NS_IMETHODIMP nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
mBounds.height = aHeight;
ResetInternalVisibility();
PRUint32 childCount, index;
if (NS_SUCCEEDED(mChildren->Count(&childCount))) {
PRInt32 childCount = mChildren.Count();
PRInt32 index;
for (index = 0; index < childCount; index++) {
nsCOMPtr<nsIWidget> childWidget;
if (NS_SUCCEEDED(mChildren->QueryElementAt(index, NS_GET_IID(nsIWidget), (void**)getter_AddRefs(childWidget)))) {
NS_STATIC_CAST(nsWidget*, NS_STATIC_CAST(nsIWidget*, childWidget.get()))->ResetInternalVisibility();
}
}
NS_STATIC_CAST(nsWidget*, mChildren[index])->ResetInternalVisibility();
}
// code to keep the window from showing before it has been moved or resized

View File

@ -101,8 +101,6 @@ nsBaseWidget::nsBaseWidget()
#ifdef DEBUG
debug_RegisterPrefCallbacks();
#endif
NS_NewISupportsArray(getter_AddRefs(mChildren));
}
@ -288,9 +286,7 @@ nsIEnumerator* nsBaseWidget::GetChildren()
{
nsIEnumerator* children = nsnull;
PRUint32 itemCount = 0;
mChildren->Count(&itemCount);
if ( itemCount ) {
if (mChildren.Count()) {
children = new Enumerator(*this);
NS_IF_ADDREF(children);
}
@ -305,7 +301,7 @@ nsIEnumerator* nsBaseWidget::GetChildren()
//-------------------------------------------------------------------------
void nsBaseWidget::AddChild(nsIWidget* aChild)
{
mChildren->AppendElement(aChild);
mChildren.AppendObject(aChild);
}
@ -316,7 +312,7 @@ void nsBaseWidget::AddChild(nsIWidget* aChild)
//-------------------------------------------------------------------------
void nsBaseWidget::RemoveChild(nsIWidget* aChild)
{
mChildren->RemoveElement(aChild);
mChildren.RemoveObject(aChild);
}
@ -331,27 +327,26 @@ NS_IMETHODIMP nsBaseWidget::SetZIndex(PRInt32 aZIndex)
// reorder this child in its parent's list.
nsBaseWidget* parent = NS_STATIC_CAST(nsBaseWidget*, GetParent());
if (nsnull != parent) {
parent->mChildren->RemoveElement(this);
PRUint32 childCount, index;
if (NS_SUCCEEDED(parent->mChildren->Count(&childCount))) {
if (parent) {
parent->mChildren.RemoveObject(this);
PRInt32 childCount = parent->mChildren.Count();
PRInt32 index;
// XXXbz would a binary search for the right insertion point be
// better? How long does this list get?
for (index = 0; index < childCount; index++) {
nsCOMPtr<nsIWidget> childWidget;
if (NS_SUCCEEDED(parent->mChildren->QueryElementAt(index, NS_GET_IID(nsIWidget), (void**)getter_AddRefs(childWidget)))) {
nsIWidget* childWidget = parent->mChildren[index];
PRInt32 childZIndex;
if (NS_SUCCEEDED(childWidget->GetZIndex(&childZIndex))) {
if (aZIndex < childZIndex) {
parent->mChildren->InsertElementAt(this, index);
parent->mChildren.InsertObjectAt(this, index);
PlaceBehind(eZPlacementBelow, childWidget, PR_FALSE);
break;
}
}
}
}
// were we added to the list?
if (index == childCount) {
parent->mChildren->AppendElement(this);
}
parent->mChildren.AppendObject(this);
}
NS_RELEASE(parent);
}
@ -1327,9 +1322,7 @@ nsBaseWidget::Enumerator::~Enumerator()
NS_IMETHODIMP
nsBaseWidget::Enumerator::Next()
{
PRUint32 itemCount = 0;
mParent.mChildren->Count(&itemCount);
if (mCurrentPosition < itemCount - 1 )
if (mCurrentPosition < mParent.mChildren.Count() - 1 )
mCurrentPosition ++;
else
return NS_ERROR_FAILURE;
@ -1356,13 +1349,8 @@ nsBaseWidget::Enumerator::CurrentItem(nsISupports **aItem)
if (!aItem)
return NS_ERROR_NULL_POINTER;
PRUint32 itemCount = 0;
mParent.mChildren->Count(&itemCount);
if ( mCurrentPosition < itemCount ) {
nsISupports* widget = mParent.mChildren->ElementAt(mCurrentPosition);
// NS_IF_ADDREF(widget); already addref'd in nsSupportsArray::ElementAt()
*aItem = widget;
}
if ( mCurrentPosition < mParent.mChildren.Count() )
NS_IF_ADDREF(*aItem = mParent.mChildren[mCurrentPosition]);
else
return NS_ERROR_FAILURE;
@ -1374,9 +1362,7 @@ nsBaseWidget::Enumerator::CurrentItem(nsISupports **aItem)
NS_IMETHODIMP
nsBaseWidget::Enumerator::First()
{
PRUint32 itemCount = 0;
mParent.mChildren->Count(&itemCount);
if ( itemCount ) {
if ( mParent.mChildren.Count() ) {
mCurrentPosition = 0;
return NS_OK;
}
@ -1391,8 +1377,7 @@ nsBaseWidget::Enumerator::First()
NS_IMETHODIMP
nsBaseWidget::Enumerator::Last()
{
PRUint32 itemCount = 0;
mParent.mChildren->Count(&itemCount);
PRInt32 itemCount = mParent.mChildren.Count();
if ( itemCount ) {
mCurrentPosition = itemCount - 1;
return NS_OK;
@ -1408,8 +1393,7 @@ nsBaseWidget::Enumerator::Last()
NS_IMETHODIMP
nsBaseWidget::Enumerator::IsDone()
{
PRUint32 itemCount = 0;
mParent.mChildren->Count(&itemCount);
PRInt32 itemCount = mParent.mChildren.Count();
if ((mCurrentPosition == itemCount-1) || (itemCount == 0) ){ //empty lists always return done
return NS_OK;

View File

@ -47,7 +47,7 @@
#include "nsIAppShell.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsISupportsArray.h"
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsGUIEvent.h"
@ -177,7 +177,7 @@ protected:
nsSizeMode mSizeMode;
// keep the list of children
nsCOMPtr<nsISupportsArray> mChildren;
nsCOMArray<nsIWidget> mChildren;
class Enumerator : public nsIBidirectionalEnumerator {
public:
@ -190,7 +190,7 @@ protected:
NS_DECL_NSIBIDIRECTIONALENUMERATOR
private:
PRUint32 mCurrentPosition;
PRInt32 mCurrentPosition;
nsBaseWidget& mParent;
};
friend class Enumerator;