Implement Layer Collection management of child layers

git-svn-id: svn://10.0.0.236/trunk@10061 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
spider%netscape.com 1998-09-15 19:50:58 +00:00
parent 06e0f20ba6
commit bafbc69717
3 changed files with 56 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "nsILayer.h"
#include "nsILayerCollection.h"
#include "nsIVector.h"
class nsLayerCollection : public nsILayerCollection,
nsILayer
@ -34,6 +35,14 @@ public:
NS_IMETHOD Init();
NS_IMETHOD CreateIterator(nsIIterator ** aIterator) ;
NS_IMETHOD AddLayer(nsILayer * aLayer);
NS_IMETHOD RemoveLayer(nsILayer * aLayer);
private:
nsIVector * mLayers ;
};
#endif //nsLayerCollection_h___

View File

@ -19,6 +19,7 @@
#define nsILayerCollection_h___
#include "nsISupports.h"
#include "nsIIterator.h"
//91cd3b90-4ccb-11d2-924a-00805f8a7ab6
#define NS_ILAYER_COLLECTION_IID \
@ -31,6 +32,13 @@ class nsILayerCollection : public nsISupports
public:
NS_IMETHOD Init() = 0;
NS_IMETHOD CreateIterator(nsIIterator ** aIterator) = 0;
NS_IMETHOD AddLayer(nsILayer * aLayer) = 0;
NS_IMETHOD RemoveLayer(nsILayer * aLayer) = 0;
};

View File

@ -17,8 +17,10 @@
*/
#include <stdio.h>
#include "nscore.h"
#include "nsLayerCollection.h"
#include "nsCoreCIID.h"
#include "nsxpfcCIID.h"
static NS_DEFINE_IID(kILayerIID, NS_ILAYER_IID);
static NS_DEFINE_IID(kILayerCollectionIID, NS_ILAYER_COLLECTION_IID);
@ -27,6 +29,8 @@ static NS_DEFINE_IID(kCLayerCollectionCID, NS_LAYER_COLLECTION_CID);
nsLayerCollection::nsLayerCollection(nsISupports* outer)
{
NS_INIT_REFCNT();
mLayers = nsnull;
}
nsresult nsLayerCollection::QueryInterface(REFNSIID aIID, void** aInstancePtr)
@ -65,12 +69,47 @@ NS_IMPL_RELEASE(nsLayerCollection)
nsLayerCollection::~nsLayerCollection()
{
// XXX: Need to add a way to remove ref when delete all!
NS_IF_RELEASE(mLayers);
}
nsresult nsLayerCollection::Init()
{
static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID);
nsresult res = nsRepository::CreateInstance(kCVectorCID,
nsnull,
kCVectorCID,
(void **)&mLayers);
if (NS_OK != res)
return res ;
mLayers->Init();
return (NS_OK);
}
nsresult nsLayerCollection :: CreateIterator(nsIIterator ** aIterator)
{
if (mLayers) {
mLayers->CreateIterator(aIterator);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult nsLayerCollection :: AddLayer(nsILayer * aLayer)
{
mLayers->Append(aLayer);
NS_ADDREF(aLayer);
return NS_OK;
}
nsresult nsLayerCollection :: RemoveLayer(nsILayer * aLayer)
{
mLayers->Remove(aLayer);
NS_IF_RELEASE(aLayer);
return NS_OK;
}