/*
 * ToolManager.h   V1.5
 *
 * 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 <graphics/gfxbase.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/layers_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.5"
#define TM_CRYEAR "1991"
#define TM_DATE "10.10.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 {
                    UWORD cb_Type;                /* Type of tool (s. below) */
                    UWORD 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_Path[BUFLEN];        /* Path string (CLI) */
                    char  cb_OutFile[BUFLEN];     /* Output file name (CLI) */
                    char  cb_HotKey[BUFLEN];      /* HotKey description */
                    char  cb_IconFile[BUFLEN];    /* Icon file name */
                    char  cb_DockFile[BUFLEN];    /* Dock image file name */
                    char  cb_TempLine[BUFLEN+20]; /* temporary line */
                   };

/* Entry for tool list */
struct ToolNode {
                 struct Node         tn_Node;     /* Node, contains name */
                 UWORD               tn_Type;     /* Type of tool (s. below) */
                 UWORD               tn_Flags;    /* Flags (see below) */
                 char               *tn_RealName; /* Real name of tool */
                 char               *tn_WorkDir;  /* Name of current dir. */
                 BPTR                tn_DirLock;  /* Directory lock */
                 char               *tn_Path;     /* Path string (CLI) */
                 char               *tn_OutFile;  /* Output file name (CLI) */
                 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 */
                 char               *tn_DockFile; /* Name of dock image file */
                 struct DiskObject  *tn_Dock;     /* Pointer to dock data */
                };

/* 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 0x0001 /* Tool has a WB menu item */
#define TNFLAGS_ICON 0x0002 /* Tool has a WB icon */
#define TNFLAGS_DOBJ 0x0004 /* The WB icon is a DiskObject */
#define TNFLAGS_NNAM 0x0008 /* The AppIcon has no name */
#define TNFLAGS_NARG 0x0010 /* Start tool with NO paramters */
#define TNFLAGS_COUT 0x0020 /* Start tool with output file (CLI tools) */
#define TNFLAGS_WBTF 0x0040 /* Workbench Screen to front before starting tool */
#define TNFLAGS_DOCK 0x0080 /* Tool has a dock */
#define TNFLAGS_SICN 0x0100 /* Dock icon same as WB icon */
#define TNFLAGS_DDOB 0x0200 /* The dock icon is a DiskObject */

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

/* Prototypes for program functions */
/* config.c */
void SetConfigFileName(char *);
void InitConfigBlock(struct ConfigBlock *);
void ReadConfigFile(char *, BOOL);
BOOL WriteConfigFile(struct Window *w, BOOL);
/* dockwindow.c */
void OpenDockWindow(void);
void CloseDockWindow(void);
void HandleDockWinEvent(void);
BOOL AddDock(struct ToolNode *);
void RemDock(struct ToolNode *);
void SelectDock(struct ToolNode *, WORD, WORD, BOOL);
struct ToolNode *FindDock(WORD, WORD);
/* editwindow.c */
void OpenEditWindow(ULONG, ULONG, ULONG, struct ToolNode *);
void CloseEditWindow(void);
void HandleEditWinEvent(void);
/* filreq.c */
BOOL ShowFileRequester(struct Window *, char *, char **, int);
BOOL ShowSaveConfigRequester(struct Window *);
/* hotkeyswindow.c */
void OpenHotKeysWindow(ULONG, ULONG);
void CloseHotKeysWindow(void);
void HandleHotKeysWinEvent(void);
void RefreshHotKeysWindow(struct ToolNode *, BOOL);
/* 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 *);
/* statuswindow.c */
void OpenStatusWindow(BOOL);
void CloseStatusWindow(void);
void HandleStatWinEvent(void);
void RefreshStatusWindow(void);
void SetBrokerState(BOOL);
void AttachToolList(void);
void DetachToolList(void);
void StatWinEndEditing(void);
void StatWinDockState(BOOL);
struct ToolNode *FindTool(void);
/* 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);

/* 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 char *IconName;
extern struct AppIcon *MyAppIcon;
extern struct AppMenuItem *OTWAppMenuItem;
extern char WBScreenName[];
extern char *ConfigName;
extern BOOL ConfigChanged;
extern struct EasyStruct SaveES;
extern BOOL ShowStatusWindow;
extern UWORD DockCount;
extern BOOL ShowDock;
extern ULONG globalsigs;
extern ULONG statwinsig;
extern ULONG editwinsig;
extern ULONG hkeywinsig;
extern ULONG dockwinsig;
extern struct MsgPort *MyBrokerPort;
extern struct Broker *MyBroker;
extern char DefaultPopUpHotKey[];
extern char *PopUpHotKey;
extern char DefaultCLIOutputFile[];
extern char *CLIOutputFile;
extern char *GlobalPath;

/* 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 */
#define STATWINAPPID   1 /* Status window AppWindow ID */
#define DOCKWINAPPID   2 /* Dock window AppWindow ID */
#define FREQ_SAVE      1 /* File requester types */
#define FREQ_FILE      2
#define FREQ_DIRS      3
#define FREQ_ICON      4
