/*===============================
|	RowNumberHandler.c
|
|	Blugs 1.1 simple handler for drawing the cell's row number
|	www.blugs.com
|
|	Copyright © 1998-2001 Brian Hall
|
|===============================*/
#ifdef __APPLE_CC__
#include <Carbon/Carbon.h>
#else
#ifndef __NUMBERFORMATTING__
#include <NumberFormatting.h>
#endif
#endif

#include "RowNumberHandler.h"
#include "BlugsappearanceExtras.h"



static void	local_RNGet( BLHandlerParamPtr param );




//===============================
pascal UInt32 RowNumberHandler(			BLMessage			message,
										BLHandlerParamPtr	param		)
{
	UInt32		answer = 0;
	
	switch (message)
	{
		case blCellDrawMsg:
		{
			Str255	nString;
			
			NumToString( param->inCell.row, nString );
			BLDrawStringVerticallyCentered( nString, &param->inRect, param->inIndent );
		}
		break;
		
		case blCellGetDataMsg:
		local_RNGet( param );
		break;
	}
	return answer;
}


//===============================
static void local_RNGet( BLHandlerParamPtr param )
{
	Str255	string;
	UInt32	bytes = 0;
	
	switch (param->ioDataFlavor)
	{
		case kRowNumberHandlerTextFlavor:
		NumToString( param->inCell.row, string );
		bytes = string[0];
		if (param->ioDataSize < bytes) bytes = param->ioDataSize;
		if (param->ioDataBuffer) BlockMoveData( &string[1], param->ioDataBuffer, bytes );
		break;
	}
	param->ioDataSize = bytes;
}