// COPYRIGHT (C) 1990-1999.  All Rights Reserved. - EVENTWN2.CPP
// Zinc Software Incorporated.  Pleasant Grove, Utah  USA
// May be freely copied, used and distributed.

#include "eventwn2.hpp"

// --- Global Functions -----------------------------------------------------

ZafEventType ExitFunction(ZafWindowObject *, ZafEventStruct &,
	ZafEventType ccode)
{
	// Put an exit message on the queue.
	if (ccode == L_SELECT)
		zafEventManager->Put(ZafEventStruct(S_EXIT));
	return (0);
}

ZafEventType StringFunction(ZafWindowObject *object, ZafEventStruct &,
	ZafEventType ccode)
{
	ZafWindowObject *trappedField = (ZafWindowObject *)object->userObject;
	if (!trappedField)
		return (ZAF_ERROR_INVALID);

	switch (ccode)
	{
		case L_SELECT:
			trappedField->SetText(ZAF_ITEXT("L_SELECT"));
			break;

		case N_CURRENT:
			trappedField->SetText(ZAF_ITEXT("N_CURRENT"));
			break;

		case N_NON_CURRENT:
			trappedField->SetText(ZAF_ITEXT("N_NON_CURRENT"));
			break;
	}

	return (0);
}

// --- BeepButton Class -----------------------------------------------------

ZafClassID BeepButton::classID = 4000;
ZafClassNameChar ZAF_FARDATA BeepButton::className[] =
	ZAF_ITEXT("BeepButton");

BeepButton::BeepButton(const ZafIChar *name, ZafObjectPersistence &persist) :
	ZafButton(name, persist)
{}

ZafEventType BeepButton::Event(const ZafEventStruct &event)
{
	ZafEventType ccode = LogicalEvent(event);
	switch (ccode)
	{
	case L_END_SELECT:
	case N_MOUSE_ENTER:
	case N_MOUSE_LEAVE:
		ZafErrorStub::Beep();
		break;
	}

	// Pass the event to the base class for processing.
 	return (ZafButton::Event(event));
}

bool BeepButton::IsA(ZafClassID compareID) const
{
	return ((compareID == classID) ? true : ZafButton::IsA(compareID));
}

bool BeepButton::IsA(ZafClassName compareName) const
{
	return (!strcmp(compareName, className) ? true : ZafButton::IsA(compareName));
}

ZafElement *BeepButton::Read(const ZafIChar *name,
	ZafObjectPersistence &persist)
{
	return (new BeepButton(name, persist));
}

// --- EventWindow Class ----------------------------------------------------

ZafClassID EventWindow::classID = 4001;
ZafClassNameChar ZAF_FARDATA EventWindow::className[] =
	ZAF_ITEXT("EventWindow");

EventWindow::EventWindow(const ZafIChar *name, ZafObjectPersistence &persist) :
	ZafWindow(name, persist)
{
	// Get pointers to the message fields.
	ZafWindowObject *string1 = GetObject("EventString1");
	ZafWindowObject *string2 = GetObject("EventString2");
	if (string1)
		string1->userObject = GetObject("LastEventTrapped1");
	if (string2)
		string2->userObject = GetObject("LastEventTrapped2");
}

ZafEventType EventWindow::Event(const ZafEventStruct &event)
{
	ZafEventType ccode = LogicalEvent(event);
	switch (ccode)
	{
	case RED_BACKGROUND:
		SetBackgroundColor(ZAF_CLR_RED);
		break;

	case GREEN_BACKGROUND:
		SetBackgroundColor(ZAF_CLR_GREEN);
		break;

	case BLUE_BACKGROUND:
		SetBackgroundColor(ZAF_CLR_BLUE);
		break;

	default:
		// Pass the event to the base class for processing.
		ccode = ZafWindow::Event(event);
		break;
	}

	return (ccode);
}

