/*
** Amster - Information
** Copyright © 1999-2000 by Gürer Özen & Jacob Laursen
**
** Maintained by Jacob Laursen <laursen@myself.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#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);
}
