/*	TErrorForm.cpp
 *
 *		Error form object
 */

/*  YAAF Constructor - Rapid application development for YAAF
 *  Copyright (C) 1998 William Edward Woody
 *  
 *  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.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <XMessages.h>
#include "TResDocument.h"
#include "TErrorView.h"
#include "TErrorForm.h"

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*	TErrorForm::TErrorForm
 *
 *		Construct me
 */

TErrorForm::TErrorForm()
{
	fError = NULL;
}

/*	TErrorForm::~TErrorForm
 *
 *		Destruct me
 */

TErrorForm::~TErrorForm()
{
	fError->window = NULL;
}

/*	TErrorForm::InitWindow
 *
 *		Initialize the window
 */

void TErrorForm::InitWindow(XGWindow *w, ErrorDeclaration *e)
{
	TErrorView *ev;
	XGDocument *doc;
	
	fError = e;

	doc = w->GetDocument();
	doc->AttachWindow(w,true);
	SetWindowName(w);
	
	ev = dynamic_cast<TErrorView *>(w->FindViewByID(1));
	doc->AddReceiver(ev);
	ev->SetFocus();
	ev->InitErrorView(e);
}

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

BEGINFORM(TErrorForm)
	DISPATCHFORM(KXGEventDocRenamed,TErrorForm::DoDocRenamed)
ENDFORM

/*	TErrorForm::DoDocRenamed
 *
 *		handle renaming the document
 */

long TErrorForm::DoDocRenamed(XGWindow *w, long, void *)
{
	SetWindowName(w);
	return 0;
}

/************************************************************************/
/*																		*/
/*	Window naming														*/
/*																		*/
/************************************************************************/

/*	TErrorForm::SetWindowName
 *
 *		Set the window's name
 */

void TErrorForm::SetWindowName(XGWindow *w)
{
	char buffer[256];
	char docname[256];
	XGDocument *doc;
	
	doc = w->GetDocument();
	if (doc) {
		doc->GetDocumentName(docname);
		sprintf(buffer,"%s: %s",docname,fError->errorResName);
		w->SetTitle(buffer);
	}
}
