/*
 * ToolManager.h   V1.4
 *
 * main include file
 *
 * (c) 1991 by Stefan Becker
 *
 */
#include <exec/types.h>
#define abs
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <exec/libraries.h>
#include <exec/memory.h>
#include <dos/dostags.h>
#include <intuition/gadgetclass.h>
#include <libraries/iffparse.h>
#include <workbench/icon.h>
#include <workbench/startup.h>

/* Prototypes for system functions */
#include <clib/alib_protos.h>
#include <clib/asl_protos.h>
#include <clib/commodities_protos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/icon_protos.h>
#include <clib/iffparse_protos.h>
#include <clib/intuition_protos.h>
#include <clib/wb_protos.h>
#undef HotKey /* Needed for -mRR */
__stkargs CxObj *HotKey(UBYTE *, struct MsgPort *, long);

/* Version number & dates */
#define TM_VERSION "1.4"
#define TM_CRYEAR "1991"
#define TM_DATE "09.07.1991"

/* Buffer lenghts */
#define BUFLEN  100 /* Buffer length for one config line */
#define NAMELEN 256 /* Buffer length for a file name */

/* Data for one config file entry */
struct ConfigBlock {
                    UBYTE cb_Type;                /* Type of tool (s. below) */
                    UBYTE cb_Flags;               /* Flags (see below) */
                    ULONG cb_Stack;               /* Stack size */
                    ULONG cb_IconX;               /* Icon X Position */
                    ULONG cb_IconY;               /* Icon Y Position */
                    char  cb_Alias[BUFLEN];       /* Alias name */
                    char  cb_RealName[BUFLEN];    /* Real name */
                    char  cb_WorkDir[BUFLEN];     /* Current directory */
                    char  cb_HotKey[BUFLEN];      /* HotKey description */
                    char  cb_IconFile[BUFLEN];    /* Icon file name */
                    char  cb_TempLine[BUFLEN+20]; /* temporary line */
                   };

/* Entry for tool list */
struct ToolNode {
                 struct Node         tn_Node;     /* Node, contains name */
                 UBYTE               tn_Type;     /* Type of tool (s. below) */
                 UBYTE               tn_Flags;    /* Flags (see below) */
                 char               *tn_RealName; /* Real name of tool */
                 char               *tn_WorkDir;  /* Name of current dir. */
                 BPTR                tn_DirLock;  /* Directory lock */
                 ULONG               tn_Stack;    /* Stack size */
                 struct AppMenuItem *tn_MenuItem; /* Pointer to WB menu item */
                 char               *tn_IconFile; /* Name of icon file */
                 struct DiskObject  *tn_Icon;     /* Pointer to icon data */
                 struct AppIcon     *tn_AppIcon;  /* Pointer to WB icon */
                 char               *tn_HotKey;   /* HotKey description */
                 CxObj              *tn_CxObj;    /* HotKey's CX Object */
                };

/* Constants for tn_Type */
#define TNTYPE_DUMMY 0  /* Non-functional dummy tool */
#define TNTYPE_CLI   1  /* CLI tool */
#define TNTYPE_WB    2  /* WB tool */

/* Flags for tn_Flags */
#define TNFLAGS_MENU 0x01 /* Tool has a WB menu item */
#define TNFLAGS_ICON 0x02 /* Tool has a WB icon */
#define TNFLAGS_DOBJ 0x04 /* The icon is a DiskObject */
#define TNFLAGS_NARG 0x08 /* Start tool with NO paramters */

/* Prototypes for library functions */
void NewList(struct List *);
struct ToolNode *GetHead(struct List *);
struct ToolNode *GetSucc(struct ToolNode *);

/* Prototypes for program functions */
/* config.c */
void SetConfigFileName(char *);
void InitConfigBlock(struct ConfigBlock *);
void ReadConfigFile(void);
void WriteConfigFile(struct Window *w);
/* editwindow.c */
void OpenEditWindow(ULONG, ULONG, ULONG, struct ToolNode *);
void CloseEditWindow(void);
void HandleEditWinEvent(void);
/* ifficon.c */
struct DiskObject *LoadIFFIcon(char *);
void FreeIFFIcon(struct DiskObject *);
/* mainloop.c */
void SetQuitFlag(void);
void mainloop(void);
/* starttools.c */
void StartTool(struct ToolNode *, struct AppMessage *);
/* toollist.c */
BOOL WBAddToolNode(struct WBArg *, int);
BOOL AddToolNode(struct ConfigBlock *,BPTR);
void RemToolNode(struct ToolNode *tn);
void RemoveTools(void);
/* toolmanager.c */
void cleanup(int);
/* statuswindow.c */
void OpenStatusWindow(void);
void CloseStatusWindow(void);
void HandleStatWinEvent(void);
void RefreshStatusWindow(void);
void AttachToolList(void);
void DetachToolList(void);

/* Global variables */
extern struct MsgPort *MyMP;
extern BPTR StartupCD;
extern BOOL ShowQuitReq;
extern BOOL running;
extern struct List ToolList;
extern UWORD ToolCount;
extern ULONG wbactive;
extern char MyName[];
extern UBYTE CopyrightNote[];
extern struct DiskObject *MyIcon;
extern LONG IconXPos,IconYPos;
extern BOOL ShowIcon;
extern struct AppIcon *MyAppIcon;
extern struct AppMenuItem *OTWAppMenuItem;
extern BOOL ShowStatusWindow;
extern ULONG statwinsig;
extern ULONG editwinsig;
extern struct MsgPort *MyBrokerPort;
extern struct Broker *MyBroker;
extern char DefaultPopUpHotKey[];
extern char *PopUpHotKey;

/* Global defines */
#define STACKMIN       4096                   /* default stack */
#define DEFPROGNAME    "ToolManager"          /* default program name */
#define DEFCONFIGNAME  "S:ToolManager.config" /* default config file name */
#define DEFPOPUPHOTKEY "rcommand help"        /* default pop up hot key */
#define WDRAGBARLEN 60 /* Width of Close & Drag gadget */
