//
//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#include "StdAfx.h"

using namespace VWFC::VWObjects;

VWObjectIterator::VWObjectIterator(MCObjectHandle hObj)
{
	fhObject	= hObj;
}

VWObjectIterator::~VWObjectIterator()
{
}

MCObjectHandle VWObjectIterator::MoveNext()
{
	VWFC_ASSERT( fhObject );
	fhObject	= ::GS_NextObject( gCBP, fhObject );
	return fhObject;
}

MCObjectHandle VWObjectIterator::MoveNextSelected()
{
	MCObjectHandle	hNextObj	= nil;
	do
	{
		hNextObj	= this->MoveNext();
	} while ( hNextObj && ! ::GS_IsSelected( gCBP, hNextObj ) );
	return hNextObj;
}

MCObjectHandle VWObjectIterator::MovePrev()
{
	VWFC_ASSERT( fhObject );
	fhObject	= ::GS_PrevObject( gCBP, fhObject );
	return fhObject;
}

MCObjectHandle VWObjectIterator::MovePrevSelected()
{
	MCObjectHandle	hNextObj	= nil;
	do
	{
		hNextObj	= this->MovePrev();
	} while ( hNextObj && ! ::GS_IsSelected( gCBP, hNextObj ) );
	return hNextObj;
}

MCObjectHandle VWObjectIterator::GetObject() const
{
	return fhObject;
}

MCObjectHandle VWObjectIterator::operator++()
{
	return this->MoveNext();
}

MCObjectHandle VWObjectIterator::operator++(int)
{
	return this->MoveNext();
}

MCObjectHandle VWObjectIterator::operator--()
{
	return this->MovePrev();
}

MCObjectHandle VWObjectIterator::operator--(int)
{
	return this->MovePrev();
}

MCObjectHandle VWObjectIterator::operator*() const
{
	return fhObject;
}

MCObjectHandle VWObjectIterator::NextObject(MCObjectHandle hObj)
{
	return ::GS_NextObject( gCBP, hObj );
}

MCObjectHandle VWObjectIterator::PrevObject(MCObjectHandle hObj)
{
	return ::GS_PrevObject( gCBP, hObj );
}

MCObjectHandle VWObjectIterator::NextSelectedObject(MCObjectHandle hObj)
{
	do {
		hObj	= ::GS_NextObject( gCBP, hObj );
	} while ( hObj && ! ::GS_IsSelected( gCBP, hObj ) );
	return hObj;
}

MCObjectHandle VWObjectIterator::PrevSelectedObject(MCObjectHandle hObj)
{
	do {
		hObj	= ::GS_PrevObject( gCBP, hObj );
	} while ( hObj && ! ::GS_IsSelected( gCBP, hObj ) );
	return hObj;
}
