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

// This example derives a class from ZafUTime and then increments the 
// time by creating a ZafTimer to notify it every second.  When the notified
// the derived UTime increments one second.

#include <zaf.hpp>
#include "timer1.hpp"

// ----- ANIMATED TIME OBJECT----------------------------------------------------

AnimatedUTime::AnimatedUTime(int left, int top, int width) :
	ZafUTime(left, top, width)
{
	SetAutoClear(false);
	SetViewOnly(true);
	SetNoncurrent(true);

	// Create a timer in the on state, set it to go off every second.
	ZafTimer *timerDevice = new ZafTimer(D_ON, 1000);

	// Add the TimeDate object to the timer list.
	timerDevice->Add(this);

	// Add the timer to the eventManger so it will be polled.
	eventManager->Add(timerDevice);

	// Set the message the timer should send.
	timerDevice->SetNotifyMessage(ONE_SECOND);

}

ZafEventType AnimatedUTime::Event(const ZafEventStruct &event)
{
	ZafEventType ccode = event.type;
	switch(ccode)
	{
	case ONE_SECOND:
		// Calling GetSystemTime() gets the system utime data.
		utimeData->GetSystemTime();
		break;
	default:
		ccode = ZafUTime::Event(event);
		break;
	}
	return(ccode);
}

// ----- Main() -------------------------------------------------------------

int ZafApplication::Main(void)
{
	// Ensure main() is linked properly.
	LinkMain();

	// Create a window and add a derived ZafUTime object to it.
	ZafWindow *window = new ZafWindow(1, 1, 33, 3);
	window->AddGenericObjects(new ZafStringData("Animated UTime Window"));
	window->Add(new AnimatedUTime(4, 1, 24));

	// Center and add the time date window.
	zafWindowManager->Center(window);
	zafWindowManager->Add(window);

	// Get the user input.
	Control();

	// Return success.
	return (0);
}

