/*
 * GHHDataList - Common header includes/defines/etc...
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

/*
** Object types --------------------------------------------------
*/
#define TYPE_STRING     0x00
#define TYPE_INTEGER    0x01
#define TYPE_INDEXED    0x02


/*
 * MESSAGE, ATTRIBUTE and VALUE IDs ------------------------------
 */
/*
** tag value range for GDataList will be 0x0400 - 0x04FF (lower 16 bits)
**                           Attributes: 0x0401 - 0x047F
**                              Methods: 0x0481 - 0x04FF
*/

#define MUIM_GHHDataList_AddRecord            0x9D590401
#define MUIM_GHHDataList_AddRecordFromArray   0x9D590402
#define MUIM_GHHDataList_Attach               0x9D590403
#define MUIM_GHHDataList_CloseFile            0x9D590404
#define MUIM_GHHDataList_OpenFile             0x9D590405
#define MUIM_GHHDataList_Remove               0x9D590406
#define MUIM_GHHDataList_ReOrganize           0x9D590407
#define MUIM_GHHDataList_Retrieve             0x9D590408
#define MUIM_GHHDataList_RetrieveArray        0x9D590409
#define MUIM_GHHDataList_Search               0x9D59040A

#define MUIA_GHHDataList_AttachCount          0x9D590481
#define MUIA_GHHDataList_DelButton            0x9D590482
#define MUIA_GHHDataList_DelConfirm           0x9D590483
#define MUIA_GHHDataList_DelResponse          0x9D590484
#define MUIA_GHHDataList_DelVerify            0x9D590485
#define MUIA_GHHDataList_Delimeter            0x9D590486
#define MUIA_GHHDataList_FileSize             0x9D590487
#define MUIA_GHHDataList_FocusObject          0x9D590488
#define MUIA_GHHDataList_FocusWindowHook      0x9D590489
#define MUIA_GHHDataList_Input                0x9D59048A
#define MUIA_GHHDataList_NewButton            0x9D59048B
#define MUIA_GHHDataList_NumSelected          0x9D59048C
#define MUIA_GHHDataList_ReOrgGainBytes       0x9D59048D
#define MUIA_GHHDataList_Sort                 0x9D59048E
#define MUIA_GHHDataList_SortPrimary          0x9D59048F
#define MUIA_GHHDataList_SortSecondary        0x9D590490
#define MUIA_GHHDataList_Titles               0x9D590491


#define MUIV_GHHDataList_AddRecord_ActiveReplace    -1
#define MUIV_GHHDataList_AddRecord_NoneReplace      -2

#define MUIV_GHHDataList_Remove_Active              -1

#define MUIV_GHHDataList_Sort_None                  -1
#define MUIV_GHHDataList_Sort_Ascending             -2
#define MUIV_GHHDataList_Sort_Descending            -3

#define MUIV_GHHDataList_VerifyMultiple             -1

#define MUIV_GHHDataList_DiskEndData   "**XPZQ*!END!*QZPX**\n"

#define GHHDataListObject MUI_NewObject(MUIC_GHHDataList



/*
 * GENERAL DEFINES ----------------------------------
 */
#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 BREAKLOOP while(1)

#define HEADERSTRING "HHDATALISTV1"
#define HEADERSIZE   12

#define LEVEL1BREAK  2
#define LEVEL2BREAK  3
#define NULLSPACE    1


/*
 * APP-TEMPLATE FUNCTION PROTOTYPES -----------------
 */
void  JMH_About( void );
LONG  JMH_Error( char *, APTR, BOOL, char *, char *, LONG );
void  JMH_InitVars( void );
void  JMH_Startup( int, char ** );
char *JMH_CStrip( char *, char * );
void  JMH_Quit( char * );
void  JMH_WindowTitle( void );
BOOL  JMH_Write( BPTR, APTR, ULONG );


/*
 * STRUCTURE DEFINITIONS ----------------------------
 */
struct NSML_Node {
   struct MinNode    mn_Node;
   ULONG             ulDiskAddr;
   ULONG             ulByteSize;
};

//
// Class Global Data Area
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct Data
{
   APTR      group;         // the object tree for this class

   LONG      lError;
   UBYTE     szError[512];

   UBYTE     szListFile[512];   // File specification
   BPTR      fhListFile;        // AmigaDOS file handle
   ULONG     ulUnusedSpace;     // NULLSPACE size in bytes
   ULONG     ulTotalSpace;      // total filesize in bytes

   SHORT     sFrameType;    // TRUE = InputListFrame; FALSE = ReadListFrame
   SHORT     sDelVerify;
   LONG      lInsertPosition;
   UBYTE     ubDelimeter;

   Object   *list;
   Object   *newbutton;
   Object   *delbutton;
   Object   *numseltext;
   Object   *pFocusObject;

   UBYTE     szNumSelected[256];
   UBYTE     szColumns[256];

   UBYTE   **ppszTitles;
   UBYTE    *pszDelButton;
   UBYTE    *pszNewButton;
   UBYTE    *pszFile;
   UBYTE    *pszNumSelected;

   UBYTE    *pszDelConfirm;
   UBYTE    *pszDelResponse;

   struct GHHDataList *pDL;
   UBYTE               ubDLIndex;     // index of next GHHDataList entry
   UBYTE               ubDLLen;       // length of DL entities ( must be < 255 )

   struct MinList    NSML;    // NullSpace memory tracking list (sorted by size/descending)
   struct MinList    NSMLDA;  // NullSpace memory tracking list (sorted by disk address)

   LONG      lSortDirection;
   LONG      lSortPrimary;
   LONG      lSortSecondary;

   struct Hook  *hDestructHook;
   struct Hook  *hDisplayHook;
   struct Hook  *hNumSelHook;
   struct Hook  *hSortHook;

   struct Hook  *hFocusWindowHook;

   APTR      hDelButton, hNewButton;
};


struct  MUIP_GHHDataList_AddRecord           { ULONG MethodID; LONG lReplaceLine; };
struct  MUIP_GHHDataList_AddRecordFromArray  { ULONG MethodID; ULONG **ppulArray; LONG lReplaceLine; };
struct  MUIP_GHHDataList_Attach              { ULONG MethodID; APTR pObj; ULONG ulAttr; ULONG ulDefaultValue;
                                               ULONG ubIsString; ULONG ubIsIndirect; APTR *ppValuesArray;
                                               ULONG ubMemOrDisk; ULONG ubInList;
                                               struct Hook *hG_Hook; struct Hook *hS_Hook; };
struct  MUIP_GHHDataList_CloseFile           { ULONG MethodID; UBYTE *pszFile; };
struct  MUIP_GHHDataList_OpenFile            { ULONG MethodID; UBYTE *pszFile; };
struct  MUIP_GHHDataList_Remove              { ULONG MethodID; LONG pos; };
struct  MUIP_GHHDataList_ReOrganize          { ULONG MethodID; UBYTE *pszTempNewFile; ULONG fReloadList; Object *pGauge; };
struct  MUIP_GHHDataList_Retrieve            { ULONG MethodID; LONG pos; };
struct  MUIP_GHHDataList_RetrieveArray       { ULONG MethodID; LONG pos; ULONG **ppulArray; };


/*
 * APPLICATION FUNCTION PROTOTYPES ------------------
 */
ULONG fnFindNodeOffset( ULONG, struct MyData * );
