/*
    NewsCoaster
    Copyright (C) 1999-2002 Mark Harman

    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

    NewsCoaster Homepage :
        http://newscoaster.tripod.com/

    Mailing List to hear about announcements of new releases etc at:
        http://groups.yahoo.com/group/newscoaster-announce/
*/

#include "mui_headers.h"

#include "Vector.h"
#include "various.h"
#include "misc.h"
#include "StatusWindow.h"

/*ASM LONG abortFunc(REG(a0) Hook * hook,REG(a2) Object * object,REG(a1) StatusWindow ** stsW) {*/
LONG HOOK3( abortFunc, Hook *, hook, a0, Object *, object, a2, StatusWindow **, stsW, a1 )
	StatusWindow * statusWindow = *stsW;
	statusWindow->setAborted(TRUE);
	return 0;
}

Hook StatusWindow::abortHook ={ {NULL,NULL},(HOOKFUNC)abortFunc,NULL,NULL};

StatusWindow::StatusWindow(Object *app,char * title) {
	this->app=app;
	this->aborted=FALSE;

	wnd = WindowObject,
		MUIA_Window_Title,			title,
		MUIA_Window_ID,				MAKE_ID('N','E','W','S'),
		MUIA_Window_CloseGadget,	FALSE,
		
		WindowContents, GROUP = VGroup,
		Child, TXT_INFO=TextObject, GroupFrame, MUIA_Text_Contents, "", MUIA_Text_PreParse, "\33c", MUIA_Text_SetMin, TRUE, End,
			Child, BT_ABORT=SimpleButton("_Abort"),
			End,
		End;
	DoMethod(app,OM_ADDMEMBER,wnd);
	DoMethod(BT_ABORT,MUIM_Notify,MUIA_Pressed,FALSE,
		app,3,MUIM_CallHook,&abortHook,this);
	set(wnd,MUIA_Window_Open,TRUE);
}

StatusWindow::~StatusWindow() {
	set(wnd,MUIA_Window_Open,FALSE);
	DoMethod(app,OM_REMMEMBER,wnd);
	MUI_DisposeObject(wnd);
}

void StatusWindow::setTitle(char * t) {
	nLog("StatusWindow::setTitle((char *)%s) called\n",t);
	set(wnd,MUIA_Window_Title,t);
}

void StatusWindow::setText(char * t) {
	strncpy(text,t,TXTLEN);
	text[TXTLEN] = '\0';
	set(TXT_INFO,MUIA_Text_Contents,text);
	/*if(DoMethod(GROUP,MUIM_Group_InitChange))
		DoMethod(GROUP,MUIM_Group_ExitChange);*/
}

void StatusWindow::resize() {
	if(DoMethod(GROUP,MUIM_Group_InitChange))
		DoMethod(GROUP,MUIM_Group_ExitChange);
}

void StatusWindow::setVisible(BOOL v) {
	set(wnd,MUIA_Window_Open,v);
}

void StatusWindow::setAborted(BOOL aborted) {
	this->aborted=aborted;
}

BOOL StatusWindow::isAborted() {
	return aborted;
}
