/*
\\
//		Library functions for editor class
\\
*/

	#include <proto/exec.h>
	#include <proto/dos.h>
	#include <proto/intuition.h>
	#include <proto/graphics.h>
	#include <proto/utility.h>
	#include <proto/muimaster.h>
	#include <proto/iffparse.h>
	#include <proto/diskfont.h>

	#include "Editor.h"

        struct ExecBase         *SysBase;
        struct DosLibrary       *DOSBase;
        struct IntuitionBase    *IntuitionBase;
        struct GfxBase          *GfxBase;
        struct Library          *MUIMasterBase;
        struct Library          *UtilityBase;
        struct Library          *IFFParseBase;
        struct Library          *DiskfontBase;
        struct MUI_CustomClass  *mcc;

ULONG SAVEDS ASM class_init( REG(a6) struct Library *libbase )
{
	DOSBase = NULL;
	IntuitionBase = NULL;
	GfxBase = NULL;
	MUIMasterBase = UtilityBase = IFFParseBase = NULL;
	mcc = NULL;

	SysBase = *((struct ExecBase **)4);
	if( !(MUIMasterBase = OpenLibrary( MUIMASTER_NAME, MUIMASTER_VMIN ) ) )
		return( -1 );
	IFFParseBase = OpenLibrary( "iffparse.library", 37 );
	if( !(mcc = MUI_CreateCustomClass( libbase, MUIC_Area, NULL, sizeof(struct ClassData), _Editor_Dispatcher ) ) )
		return( -1 );
	if( !(IntuitionBase	= (struct IntuitionBase *) mcc->mcc_IntuitionBase ) )
		return( -1 );
	DOSBase			= (struct DosLibrary *) mcc->mcc_DOSBase;
	GfxBase			= (struct GfxBase *) mcc->mcc_GfxBase;
	UtilityBase		= mcc->mcc_UtilityBase;
	DiskfontBase	= OpenLibrary( "diskfont.library", 0 );
	if( !(DOSBase && GfxBase && UtilityBase ) )
	{
		showmessage( "Missing Libraries - can't open class." );
		return( -1 );
	}

	return( NULL );
}

void SAVEDS ASM class_term( REG(a6) struct Library *libbase )
{
	if( DiskfontBase )
		CloseLibrary( DiskfontBase );
	if( mcc )
		MUI_DeleteCustomClass( mcc );
	if( IFFParseBase )
		CloseLibrary( IFFParseBase );
	if( MUIMasterBase )
		CloseLibrary( MUIMasterBase );
}

