ContentPtr Panel::getContent( const std::string contentID, int& index )
{
	for( TabItr i = tabList_.begin(); i != tabList_.end(); ++i )
	{
		Content* content = (*i)->getContent().getObject();
		if ( !content )
			continue;
		if ( contentID.compare( content->getContentID() ) == 0 )
		{
			if ( index <= 0 )
				return content;
			else
				index--;
		}
		else if ( content->getContentID() == ContentContainer::contentID &&
			((ContentContainer*)content)->contains( contentID ) )
		{
			content = ((ContentContainer*)content)->getContent( contentID, index ).getObject();
			if ( content )
				return content;
			// index already decremented by ContentContainer::getContent
		}
	}

	return 0;
}
int Panel::tabContains( TabPtr t, const std::string contentID )
{
	Content* tcontent = t->getContent().getObject();
	if ( !tcontent )
		return 0;
	
	int cnt = 0;

	if ( contentID.compare( tcontent->getContentID() ) == 0 )
		++cnt;
	else if ( tcontent->getContentID() == ContentContainer::contentID )
		cnt += ((ContentContainer*)tcontent)->contains( contentID );
	
	return cnt;
}
bool Panel::tabContains( TabPtr t, ContentPtr content )
{
	Content* tcontent = t->getContent().getObject();
	if ( !tcontent )
		return 0;
	
	return tcontent == content ||
			( tcontent->getContentID() == ContentContainer::contentID &&
			((ContentContainer*)tcontent)->contains( content ) );
}
void Panel::showTab( const std::string contentID, bool show )
{
	for( TabItr i = tabList_.begin(); i != tabList_.end(); ++i )
	{
		if ( tabContains( *i, contentID ) )
		{
			showTab( *i, show );
			Content* tcontent = (*i)->getContent().getObject();
			if ( tcontent && tcontent->getContentID() == ContentContainer::contentID )
				((ContentContainer*)tcontent)->currentContent( contentID );
		}
	}
}
void Panel::broadcastMessage( UINT msg, WPARAM wParam, LPARAM lParam )
{
	for( TabItr i = tabList_.begin(); i != tabList_.end(); ++i )
	{
		Content* content = (*i)->getContent().getObject();
		if ( !content )
			continue;

		if ( content->getContentID() == ContentContainer::contentID )
			((ContentContainer*)content)->broadcastMessage( msg, wParam, lParam );
		else
			(*i)->getCWnd()->SendMessage( msg, wParam, lParam );
	}
}