/*
 * HyperSaver - Saves AmigaGuide nodes to a new AmigaGuide file
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#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/rdargs.h>
#include <dos/dostags.h>

#include <devices/clipboard.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 <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>


#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


/*
 * MESSAGE IDs -----------------------------
 */
#define ID_MENU_NEW              101
#define ID_MENU_OPEN             102
#define ID_MENU_SAVE             103
#define ID_MENU_SAVEAS           104
#define ID_MENU_PRINT            105
#define ID_MENU_PRINTERSETUP     106
#define ID_MENU_ABOUT            107
#define ID_MENU_QUIT             108
#define ID_MENU_CUT              201
#define ID_MENU_COPY             202
#define ID_MENU_PASTE            203
#define ID_MENU_SETCON           301
#define ID_MENU_SETLOAD          302
#define ID_MENU_SETSAVE          303
#define ID_MENU_SETSAVEAS        304

#define ID_BUT_UP               1001
#define ID_BUT_DOWN             1002
#define ID_BUT_CLEARSELECTION   1003
#define ID_STR_LIST_ACK         1004
#define ID_BUT_PRINT            1005
#define ID_BUT_TEST             1006
#define ID_BUT_VIEW             1007
#define ID_LIS_LISTCHANGED      1008

#define ID_BUT_SETTSAVE         2001
#define ID_BUT_SETTUSE          2002
#define ID_BUT_SETTCANCEL       2003


/*
 * GENERAL DEFINES ----------------------------------
 */
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))

#define ENDWINDOW_OK       1
#define ENDWINDOW_CANCEL   0

#define SUCCESS 0L
#define FAILURE 1L
#define STOPRUN -1


/*
 * APP-TEMPLATE FUNCTION PROTOTYPES -----------------
 */
void  JMH_About( void );
LONG  JMH_Error( char *, APTR, char *, char *, LONG );
void  JMH_InitVars( void );
void  JMH_Startup( int, char ** );
char *JMH_Trim( char *, char *, BYTE );
void  JMH_Quit( char * );


/*
 * STRUCTURE DEFINITIONS ----------------------------
 */
struct MyGlobals {
   APTR  App;
   APTR  WIN_Main, WIN_Settings;

   struct IOClipReq   *pClipIO;
   struct MsgPort     *pClipMP;

   struct DiskObject  *dobj_App;
   char                szProjectSpec[ FMSIZE+1 ];
   char                szSettingsSpec[ FMSIZE+1 ];

   BOOL   running;
};
struct MainWindow
{
   APTR  STR_ColsPerLabel, STR_LinesPerLabel , STR_LinesTweenLabels,
         STR_List        , STR_LabelsUp      , STR_NumLabels       ,
         LIS_List        , BUT_Up            , BUT_ClearSelection  ,
         BUT_Down        , BUT_Erase         , BUT_Print           ,
         BUT_Test        , BUT_View;
};
struct SettingsWindow
{
   APTR  STR_CONString  , STR_Printer,
         BUT_Save       , BUT_Use    , BUT_Cancel;
};


/*
 * APPLICATION FUNCTION PROTOTYPES ------------------
 */
BOOL  fnConstructMainWindow    ( void );
BOOL  fnConstructSettingsWindow( void );
BOOL  fnReadDataFromDisk       ( char *, APTR, ULONG );
BOOL  fnWriteDataToDisk        ( char *, APTR );
BOOL  fnFileReq                ( APTR, char *, BOOL, char *, UWORD );
LONG  fnClipCopy               ( char * );
LONG  fnClipPaste              ( void );
void  fnPrintALabelRow         ( char * );
