/*
 * IssueTracker Common Headers   (C) 1996 John Haubrich
 *                                        All Rights Under Copyright Reserved
 *
 * Version 1.0
 *
 * Written using SAS/C 6.56
 * Using Magic User Interface (MUI) by Stefan Stuntz
 *
 * By John Haubrich
 *
 *
 * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * -------  ----        --------
 *             ;
 */

#include <exec/libraries.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/nodes.h>
#include <exec/lists.h>

#include <devices/keymap.h>

#include <graphics/gfxbase.h>
#include <graphics/displayinfo.h>

#include <intuition/intuitionbase.h>
#include <intuition/intuition.h>

#include <dos/dos.h>
#include <dos/datetime.h>
#include <dos/rdargs.h>
#include <dos/dostags.h>

#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>

#include <libraries/asl.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <libraries/gadtools.h>
#include <libraries/mui.h>

#include <rexx/storage.h>

#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>

#include <clib/alib_protos.h>

#include <proto/asl.h>
#include <proto/diskfont.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/icon.h>
#include <proto/intuition.h>
#include <proto/muimaster.h>
#include <proto/utility.h>
#include <proto/wb.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <dos.h>
#include <math.h>

#include <mui/datalist_mcc.h>
#include <mui/gdatalist_mcc.h>


/*
 * GENERAL DEFINES ----------------------------------
 */
#define  NUM_ARGS          1
#define  ARG_PROJECTFILE   0

#define FILEID_HEADER      "ISSUE TRACKER 1.0"

#define MAX( a,b )   ( ( (a) > (b) ) ? (a) : (b) )
#define MIN( a,b )   ( ( (a) < (b) ) ? (a) : (b) )
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))

#define REG(x) register __ ## x
#define ASM    __asm
#define SAVEDS __saveds

#define SimpleHelpButton(name,helpnode)\
   TextObject,\
      ButtonFrame,\
      MUIA_Text_Contents, name,\
      MUIA_Text_PreParse, "\33c",\
      MUIA_InputMode    , MUIV_InputMode_RelVerify,\
      MUIA_Background   , MUII_ButtonBack,\
      MUIA_HelpNode     , helpnode,\
      End

#define KeyHelpButton(name,key,helpnode)\
   TextObject,\
      ButtonFrame,\
      MUIA_Text_Contents, name,\
      MUIA_Text_PreParse, "\33c",\
      MUIA_Text_HiChar  , key,\
      MUIA_ControlChar  , key,\
      MUIA_InputMode    , MUIV_InputMode_RelVerify,\
      MUIA_Background   , MUII_ButtonBack,\
      MUIA_HelpNode     , helpnode,\
      End


/*
 * OBJECT IDs ------------------------------
 */
/***** MENUS *****/
#define ID_MENU_PROJECT_NEW              1010
#define ID_MENU_PROJECT_OPEN             1020
#define ID_MENU_PROJECT_SAVE             1030
#define ID_MENU_PROJECT_SAVEAS           1040
#define ID_MENU_PROJECT_PRINT            1050
#define ID_MENU_PROJECT_PRINTAS          1060
#define ID_MENU_PROJECT_HIDE             1070
#define ID_MENU_PROJECT_REVEAL           1080
#define ID_MENU_PROJECT_CLOSE            1090
#define ID_MENU_PROJECT_ABOUT            1100
#define ID_MENU_PROJECT_ABOUTMUI         1110
#define ID_MENU_PROJECT_EXITLEVEL        1120
#define ID_MENU_PROJECT_QUIT             1130

#define ID_MENU_EDIT_CUT                 2010
#define ID_MENU_EDIT_COPY                2020
#define ID_MENU_EDIT_PASTE               2030
#define ID_MENU_EDIT_ERASE               2040
#define ID_MENU_EDIT_UNDO                2050
#define ID_MENU_EDIT_REDO                2060

#define ID_MENU_MACROS_STARTLEARNING     3010
#define ID_MENU_MACROS_STOPLEARNING      3020
#define ID_MENU_MACROS_ASSIGNMACRO       3030
#define ID_MENU_MACROS_LOAD              3040
#define ID_MENU_MACROS_SAVE              3050

#define ID_MENU_SETTINGS_MUI             4010
#define ID_MENU_SETTINGS_CREATEICONS     4020
#define ID_MENU_SETTINGS_LOAD            4030
#define ID_MENU_SETTINGS_SAVE            4040
#define ID_MENU_SETTINGS_SAVEAS          4050

#define ID_MENU_USER_MACRO1              5010
#define ID_MENU_USER_MACRO2              5020
#define ID_MENU_USER_MACRO3              5030
#define ID_MENU_USER_MACRO4              5040
#define ID_MENU_USER_MACRO5              5050
#define ID_MENU_USER_MACRO6              5060
#define ID_MENU_USER_MACRO7              5070
#define ID_MENU_USER_MACRO8              5080
#define ID_MENU_USER_MACRO9              5090
#define ID_MENU_USER_MACRO10             5100


/*
 * MESSAGE IDs -----------------------------
 */

/***** WINDOW: MAIN *****/
#define ID_BUT_MAIN_NEW             10996
#define ID_BUT_MAIN_DEL             10997
#define ID_BUT_MAIN_SAVE            10998
#define ID_BUT_MAIN_APPLY           10999

#define ID_EVENT_DOUBLECLICK        10901
#define ID_EVENT_SORT               10902


/*
 * JMH-APP-TEMPLATE FUNCTION PROTOTYPES ----
 */
void    JMH_About        ( void );
LONG    JMH_Error        ( char *, APTR, BOOL, char *, char *, LONG );
BOOL    JMH_FileReq      ( APTR, UBYTE *, BOOL, BOOL, UBYTE *, UWORD );
VOID    JMH_InitVars     ( void );
void    JMH_Quit         ( char * );
void    JMH_Startup      ( int, char *[] );
void    JMH_WindowTitle  ( APTR );


/*
 * STRUCTURE DEFINITIONS -------------------
 */
#define STATUS_COUNT      6
#define PRIORITY_COUNT    4

struct MyGlobals {
   APTR  App;

   APTR  WIN_MAIN;

   UBYTE  szIssuesGrid[ STATUS_COUNT + 1 ][ PRIORITY_COUNT + 1 ][ 9 ];  // 9 digits should be enough!!!
   LONG   lIssuesGrid[ STATUS_COUNT + 1 ][ PRIORITY_COUNT + 1 ];

   struct DiskObject *dobj_App, *dobj_Proj;
   UBYTE  szProjectSpec[ FMSIZE+1 ];

   BOOL   fDataChanged;
   BOOL   running;
};

struct MainWindow {
   APTR  LV_Listview,
         DLIS_List,
         CYC_Priority,
         CYC_Status,
         STR_Description,
         MX_PriSort,
         MX_SecSort,
         CHE_Ascending,
         TXT_IssuesGrid[ STATUS_COUNT + 1 ][ PRIORITY_COUNT + 1 ],  // status, priority -- add one for totals text
         BUT_New,
         BUT_Del,
         BUT_Apply,
         BUT_Save;
};



/*
 * APPLICATION FUNCTION PROTOTYPES ------------------
 */

BOOL fnConstructMainWindow( void );
BOOL fnInitMainWindow( void );
BOOL fnDestructMainWindow( BOOL );
void fnClearMainWindow( void );

BOOL fnOpen( UBYTE * );
BOOL fnSave( UBYTE * );

void fnUpdateStatsGUI( void );
void fnCalcTotals( void );
void fnTallyRecordAdd( LONG );
void fnTallyRecordSubtract( LONG );
void fnClearStats( void );
void fnUpdateAllStats( void );



