// EIKKWIN.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <eikkwin.h>

EXPORT_C CEikKeyWindow::CEikKeyWindow()
	{
	__DECLARE_NAME(_S("CEikKeyWindow"));
	}

EXPORT_C CEikKeyWindow::~CEikKeyWindow()
	{
	if (DrawableWindow())
		Window().RemoveAllKeyRects();
	}

EXPORT_C void CEikKeyWindow::ConstructL(const TPoint& aPoint,const TSize& aSize,TInt aDeadSpaceAtStart, TInt aDeadSpaceAtEnd,TInt aScanCode,TInt aNumOfButtons,TType aType,RWindowGroup* aParent)
	{
    CreateWindowL(aParent);
	SetExtentL(aPoint,aSize);
	TSize unit=aSize;
	TPoint tl;
	// dead space adjustments
	TInt* pBreadth=(aType==EHorizontal)? &(unit.iHeight) : &(unit.iWidth);
	(*pBreadth)-=(aDeadSpaceAtStart+aDeadSpaceAtEnd);
	TInt* pAdjust=(aType==EHorizontal)? &(tl.iY) : &(tl.iX);
	(*pAdjust)+=aDeadSpaceAtStart;
	//
	TInt* pMove=(&tl.iX);
	TInt* pLength=(&unit.iWidth);
	if (aType==EVertical)
		{
		pMove=(&tl.iY);
		pLength=(&unit.iHeight);
		}
	TInt length=(*pLength);
	TInt remainder=length%aNumOfButtons;
	length/=aNumOfButtons;
	*pLength=length;
	for (TInt ii=0; ii<aNumOfButtons; ii++)
		{
		User::LeaveIfError(Window().AddKeyRect(TRect(tl,unit),aScanCode++,ETrue));
		*pMove+=length;
		if (remainder)
			{
			(*pMove)++;
			remainder--;
			}
		}
	Window().SetShadowDisabled(ETrue);
	Window().Activate();
	}
