/*===============================
|	IconHandler.c
|
|	Blugs 1.1 handler for icons - very simple
|	www.blugs.com
|
|	Copyright © 1998-2001 Brian Hall
|	You may use these routines in your software without restriction.
|
|===============================*/
#include "Blugs.h"
#include "IconHandler.h"



static void local_IconDraw( BLHandlerParamPtr param );


pascal UInt32 IconHandler( BLMessage message, BLHandlerParamPtr param )
{
	UInt32	reply = 0;
	
	switch (message)
	{
		case blHandlerInitMsg:
		reply = blWantsHilite;
		break;
		
		case blCellDrawMsg:
		local_IconDraw( param );
		break;
		
		case blCellSetDataMsg:
		if (param->ioDataFlavor == kIconResFlavor)
		{
			SInt32	data32;
			
			data32 = (SInt32)*(SInt16*)(param->ioDataBuffer);
			param->ioStorage = (Handle)data32;
		}
		break;
	}
	return reply;
}

//===============================
static void local_IconDraw( BLHandlerParamPtr param )
{
	Rect				cellRect, iconRect;
	UInt8				iconWidth = 16, iconHeight = 16;
	IconTransformType	transform = kTransformNone;
	
	cellRect = param->inRect;
	iconRect.left = cellRect.left;
	if (param->inPart != blWidgetPart) iconRect.left += param->inIndent;
	//else iconRect.left += 2;
	iconRect.right = iconRect.left + iconWidth;
	iconRect.top = cellRect.top + ((cellRect.bottom - cellRect.top - iconHeight) >> 1);
	iconRect.bottom = iconRect.top + iconHeight;
	if (!BLIsActive( param->inList)) transform = kTransformDisabled;
	if (param->inIsSelected) transform |= kTransformSelected;
	PlotIconID( &iconRect, kAlignNone, transform, (SInt16)(param->ioStorage) );
}
