/***************************************************************************/
/**                                                                       **/
/** This file contains the code to open and display the about windows     **/
/**                                                                       **/
/***************************************************************************/

#include "WAinclude.h"
#include "abouttext.h"
#include "vsion.h"
#define D(x)

//extern struct Library*	ImagePoolBase=NULL;

extern const struct NewMenu MenuData1[];
extern struct MUI_CustomClass *DTImage;
const struct Hook closeAboutHook;
enum { MenQuit=1, MenAbout, MenAboutMUI, MenMUIPrefs, MenPrefs};


/** Hooks code **/

__saveds __asm VOID debug(
	register __a0 struct Hook *hook ,
	register __a2 Object *appl ,
	register __a1 APTR *args )
{

	IP_DebugInfo(NULL);
}

__saveds __asm VOID aboutmui(
	register __a0 struct Hook *hook ,
	register __a2 Object *appl ,
	register __a1 APTR *args )
{

	APTR aboutwinMUI,menu;

	D(KPrintF("AboutMUI, %ld, %ld\n",args[0],args[1]);)

	/* create the mui about object */
	
	aboutwinMUI = AboutmuiObject,
		MUIA_Window_RefWindow, args[0],
		MUIA_Aboutmui_Application, appl,
		End;
	
	
	/*open if success */
		
	if (aboutwinMUI)
		set(aboutwinMUI,MUIA_Window_Open,TRUE);
	else
		DisplayBeep(0);
		
	/* disable the menu entry */	
		
	menu=(APTR) DoMethod(args[1],MUIM_FindUData,MenAboutMUI);
	set(menu,MUIA_Menuitem_Enabled,FALSE);

	/* enable it again when the window is closed */
	
	DoMethod(aboutwinMUI,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,menu,3,MUIM_Set,MUIA_Menuitem_Enabled,TRUE);

}

/* open and display our own aboutwindow */

__saveds __asm VOID about(
	register __a0 struct Hook *hook ,
	register __a2 Object *appl ,
	register __a1 APTR *args)
{
	Object *portobj, *aboutwin,*menu; 
	char string[155],*strp;
	
	/* create the object */
	
	aboutwin=WindowObject,
		MUIA_Window_Title, "About",
		MUIA_Window_ID   , MAKE_ID('B','O','U','T'),

		WindowContents,
			VGroup,MUIA_Background,"2:00000000,00000000,00000000",
				Child, HGroup,
					Child, NewObject(DTImage->mcc_Class,NULL,
											MUIA_DTImage_File,"images/aboutanim",
					End,
					Child,HVSpace,
						Child, TextObject,
							MUIA_Text_Contents,"\338"progname" "vsion"\nby Linus McCabe",
						End,
					Child,HVSpace,
					Child,HSpace(50),
				End,
				Child,ScrollgroupObject,
					MUIA_Background,MUII_TextBack,
					MUIA_Scrollgroup_FreeHoriz,FALSE,
					MUIA_Scrollgroup_Contents,VirtgroupObject,
						VirtualFrame,
						Child,TextObject,
							MUIA_Text_Contents, "\n\33c\33b"progname"\n"vsion"\n",
						End,
						Child,TextObject,
							MUIA_Text_Contents, "\n\nMain coding by Linus McCabe\nCopyright © 1999 by Linus McCabe\n",
						End,
						Child,portobj=TextObject,
							MUIA_Text_Contents, "Arexx Port: Zensiba",	
						End,
						Child,BalanceObject,
						End,
						Child,TextObject,
							MUIA_Text_Contents, abouttext,
						End,
					End,
				End,
			End,
		End;
		
	if(aboutwin)
	{			
		/* add the window to the application */
		DoMethod(appl,OM_ADDMEMBER,aboutwin);
		
		/* call hook when closegadget is pressed */
		DoMethod(aboutwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,appl,5,MUIM_CallHook,&closeAboutHook,aboutwin,args[0],args[1]);

		/*get the arexx port */
		get(appl,MUIA_Application_Base,&strp);
		sprintf(&string[0],"\33cArexx Port: \33b%s\n",strp);
		set(portobj,MUIA_Text_Contents,string);

		/* diable menu entry and gadget */
		menu=(APTR) DoMethod(args[0],MUIM_FindUData,MenAbout);
		set(menu,MUIA_Menuitem_Enabled,FALSE);
		set(args[1],MUIA_Disabled,TRUE);

		/* open the window */
		set(aboutwin,MUIA_Window_Open,TRUE);
		
	}

}


/* hook to close the about window */

__saveds __asm VOID closeabout(
	register __a0 struct Hook *hook ,
	register __a2 Object *appl ,
	register __a1 APTR *args)
{

	APTR menu;
	
	D(KPrintF("closeAbout, %ld, %ld\n",args[0],args[1]);)

	/* close the window */
	set(args[0],MUIA_Window_Open,FALSE);
	
	/* remove the object from the application */
	DoMethod(appl,OM_REMMEMBER,args[0]);
	
	/* dispose the object */
	DoMethod(appl,MUIM_Application_PushMethod,args[0], 1,OM_DISPOSE);

	/* enable the menu and gadget again*/
	menu=(APTR) DoMethod(args[1],MUIM_FindUData,MenAbout);
	set(menu,MUIA_Menuitem_Enabled,TRUE);
	set(args[2],MUIA_Disabled,FALSE);
}



/**** Hooks ***/

const struct Hook aboutmuiHook = {
   {NULL,NULL},
   (void *)aboutmui,
   NULL,NULL
};

const struct Hook aboutHook = {
   {NULL,NULL},
   (void *)about,
   NULL,NULL
};

const struct Hook closeAboutHook = 
{
	{NULL,NULL},
	(void *)closeabout,
	NULL,NULL
};

const struct Hook debugHook = 
{
	{NULL,NULL},
	(void *)debug,
	NULL,NULL
};
