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

// Deriving a ZAF user interface object
//
// Several members and methods must be overloaded by a derived class if
// the derivation is to include the same functionality as a ZAF base
// object.  They do NOT need to be replaced if the derivation does not
// require the specific functionality each piece provides.  Refer to the
// comments below for more information.

#include "derive.hpp"


// Summary:
// 
// Necessary overloaded functions for loading a derived class from
// persistent storage:
//   1. Persistent constructor, Read()
//   2. ClassName(), className
// 
// Optional overloaded functions:
//   3. ClassID(), classID
//   4. DynamicPtrCast(), IsA()
//
// Other (optional) members and methods:
//   5. Event()



// ** Persistent Constructor, Read()
//
// A persistent constructor is required to load an object from a Zinc
// data file.  Read() is invoked when a parent window attempts to load
// a child object and simply calls the persistent constructor.  (No code
// is required in this example since the derivation does not load custom
// data and can therefore rely solely on the base class for persistence.)

DerivedButton::DerivedButton(const ZafIChar *name, ZafObjectPersistence &persist) :
	ZafButton(name, persist)
{
	SetOSDraw(false);
}

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



// ** ClassName(), className
//
// The static className member is returned by ClassName() and is used
// as a lookup value when a persisted window loads a child.  The
// ZafObjectPersistence::ObjectConstructor table is the target of this
// lookup and a pointer to the object's Read() member is the result.
// If className and ClassName() are not overloaded, an instance of the
// ZAF base class will be created when the object is loaded by a parent
// window.  className and ClassName() are not required for any other
// purpose.

ZafClassNameChar ZAF_FARDATA DerivedButton::className[] =
	ZAF_ITEXT("DerivedButton");
// DerivedButton::ClassName() is inlined in button.hpp



// ** ClassID(), classID
// classID is returned by ClassID().  These are required only
// if DynamicPtrCast() or IsA() support are needed.

ZafClassID ZAF_FARDATA DerivedButton::classID = ID_DERIVED_BUTTON;
// ID_DERIVED_BUTTON is defined in button.hpp
// DerivedButton::ClassID() is inlined in button.hpp



// ** DynamicPtrCast(), IsA()
//
// DynamicPtrCast() requires IsA() to be overloaded.  IsA() determines
// whether an object is derived from a specified class.  Since use of
// DynamicPtrCast() is recommended for all ZAF applications, these
// methods should be overloaded.

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

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



// ** Other (optional) methods and members
//
// Other methods and members may be replaced in a derived class.
// The most commonly overloaded methods are: Event() and Draw().
// The sample below provides functionality for this simple example.

ZafEventType DerivedButton::Event(const ZafEventStruct &event)
{
	ZafEventType ccode = LogicalEvent(event);
	switch(ccode)
	{
	case N_MOUSE_ENTER:
		ZafErrorSystem::Beep();
	default:
		ccode = ZafButton::Event(event);
	}
	return (ccode);
}

ZafEventType DerivedButton::Draw(const ZafEventStruct &event,
	ZafEventType ccode)
{
	return (ZafButton::Draw(event, ccode));
}
