//	Zinc Application Framework - I_WINDOW.CPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#include "i_winmgr.hpp"

ZafWindowLink::ZafWindowLink(): childList(0), object(0)
{
}

ZafWindowLink::~ZafWindowLink()
{
	if (childList)
	{
		for (ZafElement *element = childList->First(); element;
			element = childList->First())
		{
				delete element;
		}
		delete childList;
	}
}

ZafWindowLink *ZafWindowLink::AddChild(ZafWindowObject *child)
{
	if (!childList)
		childList = new ZafListBlock(0);

	ZafWindowLink *childLink = (ZafWindowLink *)childList->Add();

	if (!childLink)
	{
		childLink = new ZafWindowLink;
		childList->ZafList::Add(childLink, childList->First());
	}
	childLink->SetObject(child);
	childList->ZafList::Subtract(childLink);
	childList->ZafList::Add(childLink, childList->First());

	return (childLink);
}

ZafWindowLink *ZafWindowLink::FirstChild(void)
{
	return (childList ? (ZafWindowLink *)childList->First() : 0);
}

ZafWindowLink *ZafWindowLink::Next(void)
{
	return ((ZafWindowLink *)next);
}

ZafWindowObject *ZafWindowLink::Object(void)
{
	return object;
}

void ZafWindowLink::SetObject(ZafWindowObject *newObject)
{
	object = newObject;
}

void ZafWindowLink::RemoveChild(ZafWindowObject *child)
{
	if (!childList)
		return;

	for (ZafWindowLink *childLink = (ZafWindowLink *)childList->First();
		childLink; childLink = childLink->Next())
	{
		if (childLink->Object() == child)
		{
			childList->Subtract(childLink);
			break;
		}
	}
}
