
#define abs
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <dos/dos.h>
#include <intuition/screens.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <libraries/asl.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/asl_protos.h>
#include <clib/alib_protos.h>
#ifdef NOTDEF
#include <db/dblib.h>
#include <db/db.h>
#include <db/dbm.h>
#include <dbm/menu_dbm.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define Prototype extern
#define Local

typedef struct Gadget	Gadget;
typedef struct Menu	Menu;
typedef struct MenuItem MenuItem;
typedef struct Window	Window;
typedef struct Screen	Screen;
typedef struct NewGadget NewGadget;
typedef struct NewMenu	 NewMenu;
typedef struct IntuiMessage IMsg;
typedef struct List	MaxList;
typedef struct Node	MaxNode;
typedef struct TextFont TextFont;
typedef struct TextAttr TextAttr;
typedef struct MsgPort	MsgPort;
typedef struct RastPort RastPort;
typedef struct StringInfo   StringInfo;
typedef struct FileRequester FileRequester;

typedef unsigned char	ubyte;
typedef unsigned short	uword;
typedef unsigned long	ulong;

typedef struct MinList	List;
typedef struct MinNode	Node;
typedef struct List	MaxList;
typedef struct Node	MaxNode;

#define STATE_WANDER	    0
#define STATE_NEWREGION     1
#define STATE_DELREGION     2
#define STATE_MOVEREGION    3
#define STATE_SIZEREGION    4
#define STATE_LINKREGION    5	/*  link from region to region	*/

#define MENU_PROJ_SAVE	    1
#define MENU_PROJ_SAVEAS    2
#define MENU_PROJ_SAVESRC   3
#define MENU_PROJ_SAVEASSRC 4
#define MENU_PROJ_LOAD	    5
#define MENU_PROJ_MERGE     6
#define MENU_PROJ_QUIT	    7

#define MENU_LINK_LOCK	    16

#define MENU_SNAP	    64

#define EGAD_TYPES	1
#define EGAD_LABPL	2
#define EGAD_NEW	3
#define EGAD_DEL	4
#define EGAD_MOVE	5
#define EGAD_SIZE	6
#define EGAD_REGNAME	7
#define EGAD_LABEL	8
#define EGAD_DEFAULT	9
#define EGAD_WANDER	10

#define EGAD_LADD	11
#define EGAD_LDEL	12
#define EGAD_ENUM	13
#define EGAD_ENUMSTR	14
#define EGAD_UPDATE	15
#define EGAD_MAXBUFLEN	16

typedef struct Box {
    short   bo_Xs;
    short   bo_Ys;
    short   bo_Xe;
    short   bo_Ye;
} Box;

typedef struct TplRegion {
    MaxNode rg_Node;		/*  region link & name	*/
    Box     rg_Box;		/*  current size	*/
    Box     rg_MinMax;		/*  min size / max size */
    uword   rg_Id;		/*  databse ID in file	*/
    Gadget  *rg_Gad;		/*  related gadget	*/
    struct TplRegion *rg_LinkLeft;
    struct TplRegion *rg_LinkRight;
    struct TplRegion *rg_LinkUp;
    struct TplRegion *rg_LinkDown;
    struct TplRegion *rg_LockedTo;
    long    rg_Flags;
    short   rg_Type;
    short   rg_MaxBufLen;	/*  maximum buffer len	*/
    long    rg_ExclGroup;	/*  exclude ID 0=disab	*/

    char    *rg_DataBase;	/*  one of		*/
    char    *rg_ListRef;
    char    **rg_CycleAry;	/*  same as ListSet	*/
    List    rg_ListSet;

    char	*rg_DefText;	    /*	default text/name   */
    char	*rg_LabText;
    TextAttr	rg_TextAttr;	    /*	font to use	    */
} TplRegion;

#define RGF_DEFERED	0x0001

#define RGT_INVISIBLE	0	/*  corresponds to CycLabels	*/
#define RGT_BUTTON	1
#define RGT_ENTRY	2
#define RGT_SELLIST	3
#define RGT_CYCLE	4


typedef struct ProjEntry {
    uword   pe_Type;
    long    pe_Len;
} ProjEntry;

typedef struct ProjHeader {
    long    ph_Magic;
    long    ph_HdrSize;
    long    ph_Version;
    Box     ph_WinDim;
    Box     ph_MinMaxDim;
    Box     ph_ZoomDim;
} ProjHeader;

typedef struct PPNode {
    Node    pp_Node;
    long    pp_Pos;
} PPNode;

#define PH_MAGIC    'TPLE'

#define PT_PROJECT	1	    /*	heirarchy   */
#define PT_HEADER	2
#define PT_REGION	3	    /*	heirarchy   */
#define PT_NAME 	4
#define PT_BOX		5
#define PT_MINMAX	6
#define PT_ID		7
#define PT_REGLL	8
#define PT_REGLR	9
#define PT_REGLU	10
#define PT_REGLD	11
#define PT_LOCKTO	12
#define PT_FLAGS	13
#define PT_TYPE 	14
#define PT_EXCLID	15
#define PT_DATABASE	16	    /*	heirarchy   */
#define PT_LISTREF	17	    /*	heirarchy   */
#define PT_LISTSET	18	    /*	heirarchy   */
#define PT_DEFTEXT	19	    /*	heirarchy   */
#define PT_TEXTATTR	20	    /*	heirarchy   */
#define PT_YSIZE	21
#define PT_LABTEXT	22	    /*	heirarchy   */
#define PT_MAXBUFLEN	23
#define PT_END		0xFFFF

extern void *GetHead();
extern void *GetSucc();

#include <tpl-protos.h>

