/****************************************************************************
*
* $RCSfile: ClickTabNodes.c $
* $Revision: 1.1 $
* $Date: 1997/09/05 13:59:23 $
* $Author: ssolie $
*
*****************************************************************************
*
* Copyright (c) 1997 Software Evolution.  All Rights Reserved.
*
*****************************************************************************
*
* ClickTabNodes.c -- Clicktab nodes source file
*
* This file contains the source code which makes using clicktab nodes
* more convenient.
*/
#include <exec/memory.h>
#include <gadgets/clicktab.h>
#include <utility/tagitem.h>

#include <proto/clicktab.h>
#include <proto/exec.h>

#include "ClickTabNodes.h"


IMPORT struct ExecBase		*SysBase;
IMPORT struct ClassLibrary	*ClickTabBase;


/****** SERL/createClickTabNodes ********************************************
*
*   NAME
*	createClickTabNodes -- Create clicktab.gadget node list
*
*   SYNOPSIS
*	nodes = createClickTabNodes(labels)
*
*	struct List *createClickTabNodes(STRPTR *);
*
*   FUNCTION
*	This function creates a list of click tab nodes for a ClassAct
*	clicktab.gadget object.  The click tab labels are supplied as an
*	array of string pointers terminated by a NULL pointer.  The click
*	tabs will be numbered starting from zero.
*
*   INPUTS
*	labels - NULL terminated array of string pointers.
*
*   RESULT
*	Pointer to a list of clicktab nodes or NULL on error.
*
*   NOTES
*	Should have the option to use a memory pool.
*
*   SEE ALSO
*	SERL/deleteClickTabNodes()
*
*****************************************************************************
*
* $RCSfile: ClickTabNodes.c $
* $Revision: 1.1 $
* $Date: 1997/09/05 13:59:23 $
* $Author: ssolie $
*
* Copyright (c) 1997 Software Evolution.  All Rights Reserved.
*
*/
struct List *createClickTabNodes(STRPTR labels[])
{
	struct List *list;
	struct Node *node;
	struct TagItem tags[3];
	WORD i;

	list = AllocVec(sizeof(struct List), MEMF_ANY);
	if ( list != NULL )  {
		NewList(list);

		tags[0].ti_Tag = TNA_Text;
		tags[1].ti_Tag = TNA_Number;
		tags[2].ti_Tag = TAG_END;

		i = 0;
		while ( labels[i] != NULL )  {
			tags[0].ti_Data = (ULONG)labels[i];
			tags[1].ti_Data = (ULONG)i;
			node = AllocClickTabNodeA(tags);
			if ( node == NULL )  {
				deleteClickTabNodes(list);
				return(NULL);
			}

			AddTail(list, node);
			i++;
		}
	}

	return(list);
}


/****** SERL/deleteClickTabNodes ********************************************
*
*   NAME
*	deleteClickTabNodes -- Delete clicktab.gadget node list
*
*   SYNOPSIS
*	deleteClickTabNodes(list)
*
*	VOID deleteClickTabNodes(struct List *);
*
*   FUNCTION
*	This function deletes a list of click tab nodes created with the
*	createClickTabNodes() function.
*
*   INPUTS
*	list - Private exec list of clicktab nodes (may be NULL).
*
*   NOTES
*	Should have the option to use a memory pool.
*
*   SEE ALSO
*	SERL/createClickTabNodes()
*
*****************************************************************************
*
* $RCSfile: ClickTabNodes.c $
* $Revision: 1.1 $
* $Date: 1997/09/05 13:59:23 $
* $Author: ssolie $
*
* Copyright (c) 1997 Software Evolution.  All Rights Reserved.
*
*/
VOID deleteClickTabNodes(struct List *list)
{
	struct Node *node;

	if ( list != NULL )  {
		while ( (node = RemHead(list)) != NULL )
			FreeClickTabNode(node);

		FreeVec(list);
	}
}
