/*
** Information
*/

#include "include/config.h"

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

#include "include/mui.h"
#include <MUI/NListview_mcc.h>

#include "include/gui.h"
#include "include/info.h"
#include "include/panel.h"
#include "amster_Cat.h"


ULONG info_new(struct IClass *cl, Object *obj, struct opSet *msg);


MUIF info_dispatch(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
{
	switch(msg->MethodID) {
		case OM_NEW: return(info_new(cl,obj,(APTR)msg));
		case INFO_MSG:
			{
			struct infodata *data = INST_DATA(cl, obj);
			DoMethod(data->msglist, MUIM_NList_InsertSingle, (char *)((muimsg)msg)->arg1, MUIV_NList_Insert_Bottom);
			set(data->msglist, MUIA_NList_First, MUIV_NList_Active_Bottom);
			return(NULL);
			}
	}
	return(DoSuperMethodA(cl,obj,msg));
}


ULONG info_new(struct IClass *cl, Object *obj, struct opSet *msg)
{
	struct infodata *data;
	Object *msglist,*clrbut;

	if (obj = (Object *)DoSuperNew(cl,obj,
		MUIA_HelpNode, "info",
		WindowContents, VGroup,
			Child, NListviewObject,
				MUIA_NListview_NList, msglist = NListObject,
					ReadListFrame,
					MUIA_NList_Input, FALSE,
					MUIA_NList_AutoCopyToClip, TRUE,
					MUIA_NList_TypeSelect, MUIV_NList_TypeSelect_Char,
					MUIA_NList_ConstructHook, MUIV_NList_ConstructHook_String,
					MUIA_NList_DestructHook, MUIV_NList_DestructHook_String,
					MUIA_NList_AutoVisible, TRUE,
				End,
			End,
			Child, HGroup,
				Child, HSpace(0),
				Child, clrbut = SimpleButton(MSG_INFO_CLEAR),
			End,
		End,
		TAG_MORE, msg->ops_AttrList))
	{
		data = INST_DATA(cl,obj);
		data->msglist = msglist;

		set(obj,MUIA_Window_ID,MAKE_ID('I','N','F','O'));
		set(obj,MUIA_Window_Title,MSG_INFO_TITLE),

		DoMethod(obj,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,gui->iconpanel,1,PANEL_CLOSEDEBUG);
		DoMethod(clrbut,MUIM_Notify,MUIA_Pressed,FALSE,msglist,1,MUIM_NList_Clear);

		return((ULONG)obj);
	}
	return(0);
}


void gui_debug(char *msg)
{
	DoMethod(gui->iwin, INFO_MSG, msg);
}


void gui_debugf(char *msg, ...)
{
	static char buf[1024];
	va_list ap;

	va_start(ap,msg);
	vsprintf(buf,msg,ap);
	va_end(ap);
	gui_debug(buf);
}
