//	Zinc Application Framework - M_KEYBRD.CPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#include <z_evtmgr.hpp>
#include <z_keybrd.hpp>
#include <z_logevt.hpp>
#include <z_string.hpp> // For strcmp().
#define ZAF_KEYBOARD_INFO
#include "gbl_def.cpp"

// ----- ZafKeyboard --------------------------------------------------------

ZafKeyboard::ZafKeyboard(ZafDeviceState _state) :
	ZafDevice(E_KEY, _state)
{
	// Initialize the keyboard device.
	installed = true;
	SetStringID(className);
	SetNumberID((ZafNumberID)classID);
}

ZafKeyboard::~ZafKeyboard(void)
{
	installed = false;
}

ZafEventType ZafKeyboard::Event(const ZafEventStruct &event)
{
	// Switch on the event type.
	ZafEventType ccode = event.type;
	switch (event.type)
	{
	case D_OFF:
	case D_ON:
		deviceState = ccode;
		break;

	case D_STATE:
		return (deviceState);
	}

	// Return the ccode.
	return (ccode);
}

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

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

void ZafKeyboard::Poll(void)
{
	// Keyboard polling is done by XtAppNextEvent().

	// This code takes events off the queue if keyboard is turned off.
	ZafEventStruct event;
	while (DeviceState() == D_OFF &&
	 eventManager->Get(event, Q_BEGIN | Q_NO_DESTROY | Q_NO_POLL | Q_NO_BLOCK) == 0 &&
	 (event.type == E_KEY || (event.type == E_MOTIF && event.InputType() == E_KEY)))
		eventManager->Get(event, Q_BEGIN | Q_NO_POLL | Q_NO_BLOCK);
}

