/*	ViewTypeRecord
 *
 *		View declaration support services
 */

/*  YAAF Constructor - Rapid application development for YAAF
 *  Copyright (C) 1998 William Edward Woody
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 *  02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <string.h>
#include "TResDocument.h"

/************************************************************************/
/*																		*/
/*	Description Objects													*/
/*																		*/
/************************************************************************/

/*	ViewTypeRecord::LenDeclaration
 *
 *		Count the number of declarations inside of this item
 */

long ViewTypeRecord::LenDeclaration()
{
	ViewTypeRecord *p;
	long count;
	
	count = 0;
	for (p = this; p != NULL; p = p->childPtr) {
		count += p->declaration->GetNumStrings();
	}
	return count;
}

/*	ViewTypeRecord::GetDeclItem
 *
 *		Get the declaration item
 */

short ViewTypeRecord::GetDeclItem(long index)
{
	unsigned char extra;
	long ix;
	
	/*
	 *	If there is a child, see if this index is inside the
	 *	child instead of me. If it is, then call the 
	 *	GetDeclItem() routine for the child. Otherwise, decrement
	 *	the index by the number of items in the child.
	 */
	
	if (childPtr) {
		ix = childPtr->LenDeclaration();
		if (index < ix) {
			return childPtr->GetDeclItem(index);
		} else {
			index -= ix;
		}
	}
	
	declaration->GetExtra(index,&extra);
	return extra;
}

/*	ViewTypeRecord::GetDeclText
 *
 *		Get the declaration item text description
 */

void ViewTypeRecord::GetDeclText(long index, char *text)
{
	long ix;
	
	/*
	 *	If there is a child, see if this index is inside the
	 *	child instead of me. If it is, then call the 
	 *	GetDeclItem() routine for the child. Otherwise, decrement
	 *	the index by the number of items in the child.
	 */
	
	if (childPtr) {
		ix = childPtr->LenDeclaration();
		if (index < ix) {
			childPtr->GetDeclText(index,text);
			return;
		} else {
			index -= ix;
		}
	}
	
	declaration->GetString(index,text);
}
