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

#include <z_table.hpp>

// ----- ZafTableHeader -----------------------------------------------------

ZafEventType ZafTableHeader::DispatchMouseEvent(const ZafEventStruct &event)
{
	ZafEventType ccode = LogicalEvent(event);

	if (modifyMode)
		return (Modify(event));

	if (windowManager->MouseEventRoute() == this)
	{
		ccode = Event(event);
		return (ccode);
	}

	if (ccode == L_BEGIN_SELECT && headerType == ZAF_ROW_HEADER)
	{
		// Convert mouse position to the coordinates of this object.
		ZafPositionStruct mousePosition = event.position;
		ZafRegionStruct windowClient = ClientRegion();
		if (windowClient.Overlap(mousePosition))
		{
			mousePosition.column -= windowClient.left;
			mousePosition.line -= windowClient.top;
			// Cast away the constness so we can have event.position relative
			// to the client region.
			((ZafEventStruct &)event).position = mousePosition;
		}
		for (ZafWindowObject *object = First(); object; object = object->Next())
			if (object->zafRegion.Overlap(mousePosition))
			{
				object->ToggleSelected();
				object->RedisplayData();

				// Update the table record.
				Table()->Get(Index(object))->SetSelected(object->Selected());
				break;
			}
	}
	else
		ccode = ZafWindow::DispatchMouseEvent(event);

	return (ccode);
}

ZafWindowObject *ZafTableHeader::FindMouseObject(const ZafEventStruct &event)
{
	return (ZafWindowObject::FindMouseObject(event));
}

// ----- OS Specific Functions ----------------------------------------------

void ZafTableHeader::OSRegisterObject(void)
{
	ZafWindow::OSRegisterObject();
}

