// EIKPARAD.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <eikparad.h>
#include <coemain.h>
#include <badesca.h>
#include <eikpriv.hrh>
#include <eikchkbx.h>
#include <eikchlst.h>
#include <eikbutb.h>
#include <txtglobl.h>
#include <txtfmlyr.h>
#include <txtfrmat.h>
#include <eikon.rsg>
#include <frmtview.h>
#include <eikbprev.h>
#include <eikfpne.h>
#include <eikenv.h>

const TInt KLineThicknessOne=20;
const TInt KLineThicknessTwo=30;
const TInt KLineThicknessThree=40;
const TInt KLineThicknessFour=50;
const TInt KLineThicknessFive=75;
const TInt KLineThicknessSix=100;
const TInt KMinIndentValue=0;


//
// CEikAlignDialog
//

EXPORT_C CEikAlignDialog::CEikAlignDialog(CParaFormat* aFormat, TParaFormatMask& aAttribChangedMask, TParaFormatMask& aUndeterminedMask)
	{
	// values passed in by app
	iAlignment=&aFormat->iHorizontalAlignment;
	iAttribChangedMask=&aAttribChangedMask;
	iUndeterminedMask=&aUndeterminedMask;
	}

void CEikAlignDialog::PreLayoutDynInitL()
	{
	CEikChoiceList* chlst = (CEikChoiceList*) (Control(EEikCidAlignList));
	if (iUndeterminedMask->AttribIsSet(EAttAlignment))
        {
		TInt index=-1;
		SetChoiceListCurrentItem(EEikCidAlignList,index);
        }
	else
		chlst->SetCurrentItem(*iAlignment);
	chlst->DrawNow();
	}

TBool CEikAlignDialog::OkToExitL(TInt /*aKeyCode*/)
	{
	if (ChoiceListCurrentItem(EEikCidAlignList)==-1) //ie if indeterminate state change nothing
		return ETrue;
    CParaFormat::TAlignment oldAlignment=*iAlignment;  // save old alignment setting
	*iAlignment=(CParaFormat::TAlignment)ChoiceListCurrentItem(EEikCidAlignList);
	if (oldAlignment!=*iAlignment || iUndeterminedMask->AttribIsSet(EAttAlignment)) // if changed or if it was indeterminate but now has a value
		iAttribChangedMask->SetAttrib(EAttAlignment);
	return (ETrue);
	}


// Indents dialog stuff
EXPORT_C CEikIndentDialog::CEikIndentDialog(CParaFormat* aFormat, TParaFormatMask& aAttribChangedMask, TParaFormatMask& aUndeterminedMask,const TInt aPageWidth)
	{
	// values passed in by app
	iLeftMargin=&aFormat->iLeftMarginInTwips;
	iRightMargin=&aFormat->iRightMarginInTwips;
	iIndent=&aFormat->iIndentInTwips;
	iAttribChangedMask=&aAttribChangedMask;
	iUndeterminedMask=&aUndeterminedMask;
	iPageWidth=aPageWidth;
	}
				  
void CEikIndentDialog::SetEditorStateL(TTextFormatAttribute aAtt,TInt aControlId,TInt32* aValue)
    {
	if (!(iUndeterminedMask->AttribIsSet(aAtt)))
		SetTwipsEditorValueL(aControlId,(TInt*)aValue);
	else 
		{
		SetTwipsEditorValueL(aControlId,NULL);
        }
    }

void CEikIndentDialog::PreLayoutDynInitL()
	{
	*iIndent+=*iLeftMargin;

	CEikTwipsEditor* left=(CEikTwipsEditor*)Control(EEikCidIndentLeftEd);
	left->SetMinMax(KMinIndentValue,iPageWidth);
	CEikTwipsEditor* right=(CEikTwipsEditor*)Control(EEikCidIndentRightEd);
	right->SetMinMax(KMinIndentValue,iPageWidth);
	CEikTwipsEditor* fline=(CEikTwipsEditor*)Control(EEikCidIndentFirstLineEd);
	fline->SetMinMax(KMinIndentValue,iPageWidth);


    SetEditorStateL(EAttLeftMargin,EEikCidIndentLeftEd,iLeftMargin);
    SetEditorStateL(EAttRightMargin,EEikCidIndentRightEd,iRightMargin);
    SetEditorStateL(EAttIndent,EEikCidIndentFirstLineEd,iIndent);
	}

TBool CEikIndentDialog::OkToExitL(TInt /*aKeyCode*/)
	{
	const TInt32 oldLeftMargin=*iLeftMargin;
	const TInt32 oldRightMargin=*iRightMargin;
	const TInt32 oldIndent=*iIndent-oldLeftMargin;

	TInt tmp=0;
	tmp=TwipsEditorValue(EEikCidIndentLeftEd);
	*iLeftMargin=tmp;
	tmp=TwipsEditorValue(EEikCidIndentRightEd);
	*iRightMargin=tmp;
	tmp=TwipsEditorValue(EEikCidIndentFirstLineEd);
	*iIndent=tmp-(*iLeftMargin);

	if (*iLeftMargin+*iRightMargin>=iPageWidth)
		iEikonEnv->LeaveWithInfoMsg(R_EIK_TBUF_INDENTS_LEFT_RIGHT_INVALID);
    if (*iRightMargin+*iIndent>=iPageWidth)
		iEikonEnv->LeaveWithInfoMsg(R_EIK_TBUF_INDENTS_RIGHT_FLINE_INVALID);		
					
	if (oldLeftMargin!=*iLeftMargin)
		iAttribChangedMask->SetAttrib(EAttLeftMargin);
	if (oldRightMargin!=*iRightMargin)
		iAttribChangedMask->SetAttrib(EAttRightMargin);
	if (oldIndent!=*iIndent)
		iAttribChangedMask->SetAttrib(EAttIndent);
	return (ETrue);
	}

//
// CEikSpaceDialog
//

EXPORT_C CEikSpaceDialog::CEikSpaceDialog(CParaFormat* aFormat, TParaFormatMask& aAttribChangedMask, TParaFormatMask& aUndeterminedMask)
	{
	iLineSpacingControl=&aFormat->iLineSpacingControl;
	iLineSpacing=&aFormat->iLineSpacingInTwips;
	iSpaceBefore=&aFormat->iSpaceBeforeInTwips;
	iSpaceAfter=&aFormat->iSpaceAfterInTwips;
	iWidowOrphan=&aFormat->iWidowOrphan;
	iKeepTogether=&aFormat->iKeepTogether;
	iKeepWithNext=&aFormat->iKeepWithNext;
	iStartNewPage=&aFormat->iStartNewPage;
	iAttribChangedMask=&aAttribChangedMask;
	iUndeterminedMask=&aUndeterminedMask;
	}

void CEikSpaceDialog::PreLayoutDynInitL()
	{
	TInt space=0;
	if (iUndeterminedMask->AttribIsSet(EAttLineSpacing))
		SetNumberEditorValue(EEikCidLineSpaceEd,NULL);
	else 
		{
		space=(*iLineSpacing+10)/20;
		SetNumberEditorValue(EEikCidLineSpaceEd,space);
		}

	if (iUndeterminedMask->AttribIsSet(EAttSpaceBefore))
		SetNumberEditorValue(EEikCidSpaceAboveEd,NULL);
	else
		{
		space=(*iSpaceBefore+10)/20;
		SetNumberEditorValue(EEikCidSpaceAboveEd,space);
		}
	if (iUndeterminedMask->AttribIsSet(EAttSpaceAfter))
		SetNumberEditorValue(EEikCidSpaceBelowEd,NULL);
	else
		{
		space=(*iSpaceAfter+10)/20;
		SetNumberEditorValue(EEikCidSpaceBelowEd,space);
		}

	TInt focusItem=-1;
	if (iUndeterminedMask->AttribIsSet(EAttLineSpacingControl))
		SetChoiceListCurrentItem(EEikCidLineSpaceList,focusItem);
	else 
		{
		TInt num=*iLineSpacingControl;
		SetChoiceListCurrentItem(EEikCidLineSpaceList,num);
		}

	CEikButtonBase::TState button=CEikButtonBase::EClear;
	if (iUndeterminedMask->AttribIsSet(EAttKeepTogether))
		button=CEikButtonBase::EIndeterminate;
	else if (*iKeepTogether)
		button=CEikButtonBase::ESet;
	SetCheckBoxState(EEikCidSpaceTogetherTkBx,button);

	button=CEikButtonBase::EClear;
	if (iUndeterminedMask->AttribIsSet(EAttKeepWithNext))
		button=CEikButtonBase::EIndeterminate;
	else if (*iKeepWithNext)
		button=CEikButtonBase::ESet;
	SetCheckBoxState(EEikCidSpaceNextTkBx,button);

	button=CEikButtonBase::EClear;
	if (iUndeterminedMask->AttribIsSet(EAttStartNewPage))
		button=CEikButtonBase::EIndeterminate;
	else if (*iStartNewPage)
		button=CEikButtonBase::ESet;
	SetCheckBoxState(EEikCidSpaceNewPageTkBx,button);

	button=CEikButtonBase::EClear;
	if (iUndeterminedMask->AttribIsSet(EAttWidowOrphan))
		button=CEikButtonBase::EIndeterminate;
	else if (*iWidowOrphan)
		button=CEikButtonBase::ESet;
	SetCheckBoxState(EEikCidSpaceWidowOrphanTkBx,button);
	}
	
TBool CEikSpaceDialog::OkToExitL(TInt /*aKeyCode*/)
	{
    CParaFormat::TLineSpacingControl oldLineSpacingControl=*iLineSpacingControl;
	const TInt32 oldLineSpacing=*iLineSpacing;
	const TInt32 oldSpaceBefore=*iSpaceBefore;
	const TInt32 oldSpaceAfter=*iSpaceAfter;
	const TBool oldWidowOrphan=*iWidowOrphan;
	const TBool oldKeepTogether=*iKeepTogether;
	const TBool oldKeepWithNext=*iKeepWithNext;
	const TBool oldStartNewPage=*iStartNewPage;

	if (ChoiceListCurrentItem(EEikCidLineSpaceList)!=-1)
		*iLineSpacingControl=(CParaFormat::TLineSpacingControl)ChoiceListCurrentItem(EEikCidLineSpaceList);
	TInt space=0;
	space=NumberEditorValue(EEikCidLineSpaceEd);
	*iLineSpacing=space*20;
	space=NumberEditorValue(EEikCidSpaceAboveEd);
	*iSpaceBefore=space*20;
	space=NumberEditorValue(EEikCidSpaceBelowEd);
	*iSpaceAfter=space*20;

	*iWidowOrphan=(CheckBoxState(EEikCidSpaceWidowOrphanTkBx)==CEikButtonBase::ESet);
	*iKeepTogether=(CheckBoxState(EEikCidSpaceTogetherTkBx)==CEikButtonBase::ESet);
	*iKeepWithNext=(CheckBoxState(EEikCidSpaceNextTkBx)==CEikButtonBase::ESet);
	*iStartNewPage=(CheckBoxState(EEikCidSpaceNewPageTkBx)==CEikButtonBase::ESet);

	if (oldLineSpacing!=*iLineSpacing)
		iAttribChangedMask->SetAttrib(EAttLineSpacing);
	if (oldLineSpacingControl!=*iLineSpacingControl)
		iAttribChangedMask->SetAttrib(EAttLineSpacingControl);
	if (oldSpaceBefore!=*iSpaceBefore)
		iAttribChangedMask->SetAttrib(EAttSpaceBefore);
	if (oldSpaceAfter!=*iSpaceAfter)
		iAttribChangedMask->SetAttrib(EAttSpaceAfter);
	if (oldWidowOrphan!=*iWidowOrphan)
		iAttribChangedMask->SetAttrib(EAttWidowOrphan);
	if (oldKeepTogether!=*iKeepTogether)
		iAttribChangedMask->SetAttrib(EAttKeepTogether);
	if (oldKeepWithNext!=*iKeepWithNext)
		iAttribChangedMask->SetAttrib(EAttKeepWithNext);
	if (oldStartNewPage!=*iStartNewPage)
		iAttribChangedMask->SetAttrib(EAttStartNewPage);
	
	return (ETrue);
	}

//
// CEikBorderDialog
//

EXPORT_C CEikBorderDialog::CEikBorderDialog(CParaFormat* aFormat, TParaFormatMask& aAttribChangedMask, TParaFormatMask& aUndeterminedMask)
	: iFormat(aFormat),
	iAttribChangedMask(&aAttribChangedMask),
	iUndeterminedMask(&aUndeterminedMask),
	iRightBorder(aFormat->ParaBorder(CParaFormat::EParaBorderRight)),
	iLeftBorder(aFormat->ParaBorder(CParaFormat::EParaBorderLeft)),
	iTopBorder(aFormat->ParaBorder(CParaFormat::EParaBorderTop)),
	iBottomBorder(aFormat->ParaBorder(CParaFormat::EParaBorderBottom)),
	iBorderMargin(&aFormat->iBorderMarginInTwips),
	iOldLeftBorder(iLeftBorder),  // keep for comparison later
	iOldRightBorder(iRightBorder),
	iOldTopBorder(iTopBorder),
	iOldBottomBorder(iBottomBorder),
	//color
	iFillColor(aFormat->iFillColor),
	iOldFillColor(iFillColor)
	{}

void CEikBorderDialog::PreLayoutDynInitL()
	{
	SetBorderLineStyleAndColor(iLeftBorder, EAttLeftBorder,EEikCidBorderLeft, (ControlOrNull(EEikCidColorLeftBorder)!=NULL ? EEikCidColorLeftBorder : EEikCidColorLeftBorder2));	
	//right border linestyle
	SetBorderLineStyleAndColor(iRightBorder, EAttRightBorder,EEikCidBorderRight, (ControlOrNull(EEikCidColorRightBorder)!=NULL ? EEikCidColorRightBorder : EEikCidColorRightBorder2));	
	//Top border linestyle
	SetBorderLineStyleAndColor(iTopBorder, EAttTopBorder,EEikCidBorderTop, (ControlOrNull(EEikCidColorTopBorder)!=NULL ? EEikCidColorTopBorder : EEikCidColorTopBorder2));	
	//bottom border linestyle
	SetBorderLineStyleAndColor(iBottomBorder, EAttBottomBorder,EEikCidBorderBottom, (ControlOrNull(EEikCidColorBottomBorder)!=NULL ? EEikCidColorBottomBorder : EEikCidColorBottomBorder2));	
   //textmargin
	SetTwipsEditorValueL(EEikCidBorderMarginEd,(TInt*)iBorderMargin);
	//background color
	TInt colorFocusItem= (ControlOrNull(EEikCidColorBackground)!=NULL ? ConvertTRgbToGray(iFillColor) : iFillColor.Color16()); //ConvertTRgbToGray(iFillColor);
	if (iUndeterminedMask->AttribIsSet(EAttFillColor))
       colorFocusItem=-1; // focus on empty string
	SetChoiceListCurrentItem((ControlOrNull(EEikCidColorBackground)!=NULL ? EEikCidColorBackground : EEikCidColorBackground2),colorFocusItem);
	DoPreview();
	}
		  
void CEikBorderDialog::SetBorderLineStyleAndColor(const TParaBorder& aBorder,TTextFormatAttribute aAttribute,TInt aControlId, TInt aColorControlId)
	{
	const TBool attribIsSet=iUndeterminedMask->AttribIsSet(aAttribute);
	SetChoiceListCurrentItem(aControlId,(attribIsSet? -1 : GetTBorderStyle(aBorder)));
	SetChoiceListCurrentItem(aColorControlId,(attribIsSet? -1 : (aColorControlId <= 12 ? ConvertTRgbToGray(aBorder.iColor) : aBorder.iColor.Color16())));
	}

CEikBorderDialog::TBorderStyle CEikBorderDialog::GetTBorderStyle(TParaBorder aBorder)
	{
	TParaBorder::TLineStyle borderStyle=aBorder.iLineStyle;
	const TInt lineThickness=aBorder.iThickness;
	
	switch (borderStyle)
		{
	case TParaBorder::ENullLineStyle:
		 return ENullLineStyle;
	case TParaBorder::ESolid:
		if (lineThickness==KLineThicknessOne)
			return ESolid1;
		else if (lineThickness==KLineThicknessTwo)
			return ESolid2;
		else if (lineThickness==KLineThicknessThree)
			return ESolid3;
		else if (lineThickness==KLineThicknessFour)
			return ESolid4;
		else if (lineThickness==KLineThicknessFive)
			return ESolid5;
		else if (lineThickness==KLineThicknessSix)
			return ESolid6;
	case TParaBorder::EDouble:
		if (lineThickness==KLineThicknessOne)
			return EDouble1;
		else if (lineThickness==KLineThicknessTwo)
			return EDouble2;
		else if (lineThickness==KLineThicknessThree)
			return EDouble3;
	case TParaBorder::EDotted:
		return EDotted;
	case TParaBorder::EDashed:
		return EDashed;
	case TParaBorder::EDotDash:
		return EDotDash;
	case TParaBorder::EDotDotDash:
		return EDotDotDash;
	default:
		return ENullLineStyle;
		}
	}
		

TBool CEikBorderDialog::OkToExitL(TInt /*aKeyCode*/)
	{
	if (iLeftBorder!=iOldLeftBorder)
		{
		iFormat->SetParaBorderL(CParaFormat::EParaBorderLeft, iLeftBorder);
		iAttribChangedMask->SetAttrib(EAttLeftBorder);
		}
	if (iRightBorder!=iOldRightBorder)
		{
		iFormat->SetParaBorderL(CParaFormat::EParaBorderRight, iRightBorder);
		iAttribChangedMask->SetAttrib(EAttRightBorder);
		}
	if (iTopBorder!=iOldTopBorder)
		{
		iFormat->SetParaBorderL(CParaFormat::EParaBorderTop, iTopBorder);
		iAttribChangedMask->SetAttrib(EAttTopBorder);
		}
	if (iBottomBorder!=iOldBottomBorder)
		{
		iFormat->SetParaBorderL(CParaFormat::EParaBorderBottom, iBottomBorder);
		iAttribChangedMask->SetAttrib(EAttBottomBorder);
		}
	if (iFillColor!=iOldFillColor)
		{
		iFormat->iFillColor=iFillColor;
		iAttribChangedMask->SetAttrib(EAttFillColor);
		}
	const TInt32 oldBorderMargin=*iBorderMargin;
	*iBorderMargin=TwipsEditorValue(EEikCidBorderMarginEd);
	if (oldBorderMargin!=*iBorderMargin)
		iAttribChangedMask->SetAttrib(EAttBorderMargin);
	return (ETrue);
	}


void CEikBorderDialog::HandleControlStateChangeL(TInt aControlId)
	{
	TBorderStyle lineStyle;
	TInt gray=0;
	if (aControlId==EEikCidBorderMarginEd)
		return;
	switch(aControlId)
		{
	case EEikCidBorderLeft:
		lineStyle=(TBorderStyle)ChoiceListCurrentItem(EEikCidBorderLeft);
		iLeftBorder.iLineStyle=GetLineStyle(lineStyle);
		iLeftBorder.iThickness=GetLineThickness(lineStyle);
		break;
	case EEikCidBorderRight:
		lineStyle=(TBorderStyle)ChoiceListCurrentItem(EEikCidBorderRight);
		iRightBorder.iLineStyle=GetLineStyle(lineStyle);
		iRightBorder.iThickness=GetLineThickness(lineStyle);
		break;
	case EEikCidBorderTop:
		lineStyle=(TBorderStyle)ChoiceListCurrentItem(EEikCidBorderTop);
		iTopBorder.iLineStyle=GetLineStyle(lineStyle);
		iTopBorder.iThickness=GetLineThickness(lineStyle);
		break;
	case EEikCidBorderBottom:
		lineStyle=(TBorderStyle)ChoiceListCurrentItem(EEikCidBorderBottom);
		iBottomBorder.iLineStyle=GetLineStyle(lineStyle);
		iBottomBorder.iThickness=GetLineThickness(lineStyle);
		break;
	case EEikCidColorBackground:
		gray=ChoiceListCurrentItem(EEikCidColorBackground);
		iFillColor=ConvertGrayToTRgb(gray);
		break;
	case EEikCidColorLeftBorder:
		gray=ChoiceListCurrentItem(EEikCidColorLeftBorder);
		iLeftBorder.iColor=ConvertGrayToTRgb(gray);
		iLeftBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorRightBorder:
		gray=ChoiceListCurrentItem(EEikCidColorRightBorder);
		iRightBorder.iColor=ConvertGrayToTRgb(gray);
		iRightBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorTopBorder:
		gray=ChoiceListCurrentItem(EEikCidColorTopBorder);
		iTopBorder.iColor=ConvertGrayToTRgb(gray);
		iTopBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorBottomBorder:
		gray=ChoiceListCurrentItem(EEikCidColorBottomBorder);
		iBottomBorder.iColor=ConvertGrayToTRgb(gray);
		iBottomBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorBackground2:
		gray=ChoiceListCurrentItem(EEikCidColorBackground2);
		iFillColor=TRgb::Color16(gray); 
		break;
	case EEikCidColorLeftBorder2:
		gray=ChoiceListCurrentItem(EEikCidColorLeftBorder2);
		iLeftBorder.iColor=TRgb::Color16(gray); 
		iLeftBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorRightBorder2:
		gray=ChoiceListCurrentItem(EEikCidColorRightBorder2);
		iRightBorder.iColor=TRgb::Color16(gray); 
		iRightBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorTopBorder2:
		gray=ChoiceListCurrentItem(EEikCidColorTopBorder2);
		iTopBorder.iColor=TRgb::Color16(gray); 
		iTopBorder.iAutoColor=EFalse; 
		break;
	case EEikCidColorBottomBorder2:
		gray=ChoiceListCurrentItem(EEikCidColorBottomBorder2);
		iBottomBorder.iColor=TRgb::Color16(gray);
		iBottomBorder.iAutoColor=EFalse; 
		break;
		}
	DoPreview();		 
	}

TParaBorder::TLineStyle CEikBorderDialog::GetLineStyle(TBorderStyle aLineStyle)
	{
	// converts linestyle chosen from the choicelist enum into TParaBorder linestyle
	switch (aLineStyle)
		{
	case ENullLineStyle:
		return TParaBorder::ENullLineStyle;
	case ESolid1:
	case ESolid2:
	case ESolid3:
	case ESolid4:
	case ESolid5:
	case ESolid6:
		return TParaBorder::ESolid;
	case EDouble1:
	case EDouble2:
	case EDouble3:
		return TParaBorder::EDouble;
	case EDotted:
		return TParaBorder::EDotted;
	case EDashed:
		return TParaBorder::EDashed;
	case EDotDash:
		return TParaBorder::EDotDash;
	case EDotDotDash:
		return TParaBorder::EDotDotDash;
	default:
		return TParaBorder::ENullLineStyle;
		}
	}

TInt CEikBorderDialog::GetLineThickness(TBorderStyle aLineStyle)
	{
	// converts linestyle chosen from choicelist to correct thickness for TParaBorder
	switch (aLineStyle)
		{
		case ENullLineStyle:
			return 0;
		case ESolid1:
		case EDouble1:
			return KLineThicknessOne;
		case ESolid2:
		case EDouble2:
			return KLineThicknessTwo;
		case ESolid3:
		case EDouble3:
			return KLineThicknessThree;
		case ESolid4:
			return KLineThicknessFour;
		case ESolid5:
			return KLineThicknessFive;
		case ESolid6:
			return KLineThicknessSix;
		default:		  // all others assume thickness 1
			return 1;
		}
	}

void CEikBorderDialog::DoPreview()
	{
	TParaBorderArray borderArray;

	borderArray.iBorder[0]=iTopBorder;
	borderArray.iBorder[1]=iBottomBorder;
	borderArray.iBorder[2]=iLeftBorder;
	borderArray.iBorder[3]=iRightBorder;
	CEikBorderPreview* preview=(CEikBorderPreview*) (Control(EEikCidBorderPreview));
	CEikBorderPreview* previewcolor=(CEikBorderPreview*) (Control(EEikCidBorderColorPreview));
	preview->SetUp(borderArray, &iFillColor);
	previewcolor->SetUp(borderArray, &iFillColor);
	preview->HandleChange();
	previewcolor->HandleChange();
	}
	
TInt CEikBorderDialog::ConvertTRgbToGray(TRgb aTRgb)
	{	//this code should change if the grey selector changes
	const TInt value=aTRgb.Gray4();
	return (value<4? value+1: 0);
	}

TRgb CEikBorderDialog::ConvertGrayToTRgb(TUint aGray)
	{ 
	switch (aGray)
		{
	case 1:
		return TRgb(0,0,0);			// black
	case 2:
		return TRgb(85,85,85);		// dark gray
	case 3:
		return TRgb(170,170,170);	// light gray
	case 4:
		return TRgb(255,255,255);	// white
	default:
		return TRgb(255,255,255);	// default = white
		}
	}

