#include "PrintInf.h"
#include "XBox.h"
#include "Runtime.h"

void TPrintInf::Init(int x1, int y1, int aW, int aH, int OwnerX, int OwnerY, u32 aColor)
{
	#define CH	30	//Caption Height
	unsigned short Left,Right, Top, Bottom, Width, Height, i;
	Bound.SetBySize(OwnerX + x1, OwnerY + y1, aW, aH);
	Left = Bound.Left +3;
	Top = Bound.Top+3;
	Width = aW - 7;
	Height = aH - 7;
	Right = Bound.Right -4;
	Bottom = Bound.Bottom -4;
	BoundCaption.SetBySize(Left,Top,Width, CH);
	Content.Set(Left, Top+CH, Right, Bottom);
	
	BoxBound.Set(Left + 100, Top+70, Right -400, Bottom -70);
	BoxBoundTime.Set(Left + 400, Top+70, Right -60, Bottom -70);
	
	WhatSel = 0;
	SelectedFromOrEnd = 0;
	SelectedIndex =0;
	IsEditing = 0;
	
	InfList[0] = 0xA5;
	InfList[1] = 0xA5;
	InfList[2] = 0xA5;
	InfList[3] = 0xA5;
	InfList[4] = 0xA5;
	
	vtValueFrom[0] = 0;
	vtValueFrom[1] = 0;
	vtValueFrom[2] = 0;
	vtValueFrom[3] = 0;
	vtValueFrom[4] = 0;
	vtValueFrom[5] = 0;
	vtValueTo[0] = 0;
	vtValueTo[1] = 0;
	vtValueTo[2] = 0;
	vtValueTo[3] = 0;
	vtValueTo[4] = 0;
	vtValueTo[5] = 0;

	IsPermission =0;
	
	#undef CH
}

void TPrintInf::DrawSelf(void)
{
	unsigned int x, y, x2, y2, w, h;
	
	VertLineRender(Bound.Left,		Bound.Top, 			Bound.Height -1,			0xFFFFFFFF);
	VertLineRender(Bound.Right -1,	Bound.Top +1,		Bound.Height -2,			0xFF808080);
	VertLineRender(Bound.Right,		Bound.Top,			Bound.Height,			0xFF404040);
	
	HorizLineRender(Bound.Left, 		Bound.Top, 			Bound.Width - 1, 			0xFFFFFFFF);
	HorizLineRender(Bound.Left +1, 	Bound.Bottom -1,  	Bound.Width - 2, 			0xFF808080);
	HorizLineRender(Bound.Left,		Bound.Bottom,		Bound.Width,			0xFF404040);
	
	x = Bound.Left +2 ;	
	x2 = Bound.Right -2;
	y = Bound.Top +2;
	y2 = Bound.Bottom - 2;
	w = Bound.Width -4;
	h = Bound.Height - 4;
	VertLineRender	(x,		y, 		h-1,	0xFF808080);
	HorizLineRender	(x,		y, 		w-1,	0xFF808080);
		
	VertLineRender	(x+1,		y+1, 		h-2,	0xFF404040);
	HorizLineRender	(x+1,		y+1, 		w-2,	0xFF404040);
	
	VertLineRender	(x2-1,	y+1, 		h-2,	0xFFD4D0C8);
	HorizLineRender	(x+1,		y2-1, 	w-2,	0xFFD4D0C8);

	VertLineRender	(x2,		y, 	  	h,	0xFFFFFFFF);
	HorizLineRender	(x,		y2, 		w,	0xFFFFFFFF);
	
	RectFillRender(Content.Left, Content.Top, Content.Right, Content.Bottom, clFrmFace);
	
	RectFillRender(BoundCaption.Left, BoundCaption.Top, BoundCaption.Right, BoundCaption.Bottom, clMaroon);
	if(LanguageEnCn==0)TextRender_string24(BoundCaption.Left+6, BoundCaption.Top +3, clNearWhite, clMaroon, 	"历史信息->打印     按TAB键切换选定框"); 
	else TextRender_string24(BoundCaption.Left+6, BoundCaption.Top +3, clNearWhite, clMaroon, 			"Recorded Information->Print");
}


void TPrintInf::Show(void)
{
	DrawSelf();
	DrawBoxItems();
	ReDrawItems();
	DrawWidget();
	
	DrawBoxTime();
	DrawBoxTimeString();
	DrawSaveButton();
}

void TPrintInf::FullRedraw(int Prm)
{
	if(Prm == 0){
		DrawSelf();
		DrawBoxItems();
		ReDrawItems();
		DrawWidget();
		
		RectFillRender(BoxBoundTime.Left, 	BoxBoundTime.Top, BoxBoundTime.Right, BoxBoundTime.Bottom, clFrmFace);
		DrawBoxTimeOutLine();
		DrawTimeEntryNoUpdate();
		DrawBoxTimeString();
		DrawSaveButton();
		if(WhatSel == 1){
			SetEditStart();
		}
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], clFrmFace);
		DrawBoxItems();
		ReDrawItems();
		DrawWidget();
		
		RectFillRender(BoxBoundTime.Left, 	BoxBoundTime.Top, BoxBoundTime.Right, BoxBoundTime.Bottom, clFrmFace);
		DrawBoxTimeOutLine();
		DrawTimeEntryNoUpdate();
		DrawBoxTimeString();
		DrawSaveButton();
		if(WhatSel == 1){
			SetEditStart();
		}
		if(WhatSel == 3)ShowDetial();
		
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
		
	}
}

void TPrintInf::PermissionCmdReturnDraw()
{
	RectFillRender(200-10, 86-10, 600+20, 220, clFrmFace);
	DrawBoxItems();
	ReDrawItems();
	DrawWidget();
	
	RectFillRender(BoxBoundTime.Left, 	BoxBoundTime.Top, BoxBoundTime.Right, BoxBoundTime.Bottom, clFrmFace);
	DrawBoxTimeOutLine();
	DrawTimeEntryNoUpdate();
	DrawBoxTimeString();
	DrawSaveButton();
	if(WhatSel == 1){
		SetEditStart();
	}
	ShowDetial();
}

void TPrintInf::GetStartStopTime()
{
	int i;	
	for(i=0; i<6;i++){
		alt.D8[5-i] = (vtTextFrom[i][0] - '0') * 16;
		alt.D8[5-i] += (vtTextFrom[i][1] - '0');
		
	}
	alt.D8[6] = 0;
	alt.D8[7] = 0;
	StartTime = alt.D64;
	
	for(i=0; i<6;i++){
		alt.D8[5-i] = (vtTextTo[i][0] - '0') * 16;
		alt.D8[5-i] += (vtTextTo[i][1] - '0');
		
	}
	alt.D8[6] = 0;
	alt.D8[7] = 0;
	StopTime = alt.D64;
}
	
void TPrintInf::PermissionCmdGO()
{	
	GoPrint();
}

void TPrintInf::ShowDetial()
{
	int x,y,x2,y2,aW,aH;
	unsigned int tClr;
	char *tText;
	x = Bound.Left + 196;
	y = Bound.Top + 60 ;
	aW = 400;
	aH = 260;
	x2 = x + aW -1;
	y2 = y + aH -1;
	
	RectFillRender(x, y, x2, y2, clFrmFace);
	
	VertLineRender(x,		y, 		aH -1,		0xFFFFFFFF);
	VertLineRender(x2 -1,	y +1,		aH -2,		0xFF808080);
	VertLineRender(x2,	y,		aH,			0xFF404040);
	
	HorizLineRender(x, 	y, 		aW - 1, 		0xFFFFFFFF);
	HorizLineRender(x +1, 	y2 -1,  	aW - 2, 		0xFF808080);
	HorizLineRender(x,	y2,		aW,			0xFF404040);
	
	if(LanguageEnCn==0)tText="按确定键打印, 按返回键返回";
	else tText= "Press 'OK' Key To Print, Or Return";
	TStaticText::sShow(x+2, y+2, x2-2, y+32, clNearWhite, clBlue,  tText);
	
	x = x +60;
	y = y + 50;
	tClr = InfList[0] ? clNearBlack : clSilver;
	if(LanguageEnCn==0)tText="火警信息"; else tText="Fire Alram";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText); 
	TextDigitRender6Right24(x +180, y, tClr, this->CountFire);
	y = y + 32;
	tClr = InfList[1] ? clNearBlack : clSilver;
	if(LanguageEnCn==0)tText="联动信息"; else tText="Linkage   ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);
	TextDigitRender6Right24(x +180, y, tClr, this->CountLinkage);
	y = y + 32;
	tClr = InfList[2] ? clNearBlack : clSilver;
	if(LanguageEnCn==0)tText="监管信息"; else tText="Supv      ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText); 
	TextDigitRender6Right24(x +180, y, tClr, this->CountSv);
	y = y + 32;
	tClr = InfList[3] ? clNearBlack : clSilver;
	if(LanguageEnCn==0)tText="故障信息"; else tText="Fault     ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);
	TextDigitRender6Right24(x +180, y, tClr, this->CountFault);
	y = y + 32; 
	tClr = InfList[4] ? clNearBlack : clSilver;
	if(LanguageEnCn==0)tText="操作信息"; else tText="Operating ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);
	TextDigitRender6Right24(x +180, y, tClr, this->CountOperate);
	y = y + 32; 
	TextRender_string24(x, y, clNearBlack, clFrmFace, "Total Records");
	TextDigitRender6Right24(x +180, y, clNearBlack, this->Count2Print);
}

void TPrintInf::ReDrawItems()
{
	int x,y;
	unsigned int aClr;
	char *tText;
	x = BoxBound.Left + 24 + 20;
	y = BoxBound.Top + 36 ;
	
	if(LanguageEnCn==0)tText="火警信息"; else tText="Fire Alram";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);  
	y = y + 36;
	if(LanguageEnCn==0)tText="联动信息"; else tText="Linkage   ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);
	y = y + 36;
	if(LanguageEnCn==0)tText="监管信息"; else tText="Supv      ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText); 
	y = y + 36;
	if(LanguageEnCn==0)tText="故障信息"; else tText="Fault     ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);
	y = y + 36; 
	if(LanguageEnCn==0)tText="操作信息"; else tText="Operating ";
	TextRender_string24(x, y, clNearBlack, clFrmFace, tText);
}

void TPrintInf::DrawWidget()
{
	int x,y,R;
	x = BoxBound.Left + 24;
	y = BoxBound.Top + 36 +12;
	R = 10;
	
	#define CLR_SEL	clBlue
	#define CLR_ACT	clGreen
	
	if(FocusIndex == 0){
		TCircle::sRender(x, y, R+2, CLR_SEL, 0);
		TCircle::sRender(x, y, R+3, CLR_SEL, 0);
		TCircle::sRender(x, y, R+4, CLR_SEL, 0);
	}else{
		TCircle::sRender(x, y, R+2, clFrmFace, 0);
		TCircle::sRender(x, y, R+3, clFrmFace, 0);
		TCircle::sRender(x, y, R+4, clFrmFace, 0);
	}
	TCircle::sRender(x, y, R, clGray, 0);
	if(InfList[0]){
		TCircle::sRender(x, y, R-1, CLR_ACT, 1);
	}else{
		TCircle::sRender(x, y, R-1, clFrmFace, 1);
	}
	
	y = y+36;
	if(FocusIndex == 1){
		TCircle::sRender(x, y, R+2, CLR_SEL, 0);
		TCircle::sRender(x, y, R+3, CLR_SEL, 0);
		TCircle::sRender(x, y, R+4, CLR_SEL, 0);
	}else{
		TCircle::sRender(x, y, R+2, clFrmFace, 0);
		TCircle::sRender(x, y, R+3, clFrmFace, 0);
		TCircle::sRender(x, y, R+4, clFrmFace, 0);
	}
	TCircle::sRender(x, y, R, clGray, 0);
	if(InfList[1]){
		TCircle::sRender(x, y, R-1, CLR_ACT, 1);
	}else{
		TCircle::sRender(x, y, R-1, clFrmFace, 1);
	}
	
	y = y+36;
	if(FocusIndex == 2){
		TCircle::sRender(x, y, R+2, CLR_SEL, 0);
		TCircle::sRender(x, y, R+3, CLR_SEL, 0);
		TCircle::sRender(x, y, R+4, CLR_SEL, 0);
	}else{
		TCircle::sRender(x, y, R+2, clFrmFace, 0);
		TCircle::sRender(x, y, R+3, clFrmFace, 0);
		TCircle::sRender(x, y, R+4, clFrmFace, 0);
	}
	TCircle::sRender(x, y, R, clGray, 0);
	if(InfList[2]){
		TCircle::sRender(x, y, R-1, CLR_ACT, 1);
	}else{
		TCircle::sRender(x, y, R-1, clFrmFace, 1);
	}
	
	y = y+36;
	if(FocusIndex == 3){
		TCircle::sRender(x, y, R+2, CLR_SEL, 0);
		TCircle::sRender(x, y, R+3, CLR_SEL, 0);
		TCircle::sRender(x, y, R+4, CLR_SEL, 0);
	}else{
		TCircle::sRender(x, y, R+2, clFrmFace, 0);
		TCircle::sRender(x, y, R+3, clFrmFace, 0);
		TCircle::sRender(x, y, R+4, clFrmFace, 0);
	}
	TCircle::sRender(x, y, R, clGray, 0);
	if(InfList[3]){
		TCircle::sRender(x, y, R-1, CLR_ACT, 1);
	}else{
		TCircle::sRender(x, y, R-1, clFrmFace, 1);
	}
	
	y = y+36;
	if(FocusIndex == 4){
		TCircle::sRender(x, y, R+2, CLR_SEL, 0);
		TCircle::sRender(x, y, R+3, CLR_SEL, 0);
		TCircle::sRender(x, y, R+4, CLR_SEL, 0);
	}else{
		TCircle::sRender(x, y, R+2, clFrmFace, 0);
		TCircle::sRender(x, y, R+3, clFrmFace, 0);
		TCircle::sRender(x, y, R+4, clFrmFace, 0);
	}
	TCircle::sRender(x, y, R, clGray, 0);
	if(InfList[4]){
		TCircle::sRender(x, y, R-1, CLR_ACT, 1);
	}else{
		TCircle::sRender(x, y, R-1, clFrmFace, 1);
	}
}

void TPrintInf::DrawBoxItemsOutLine(void)
{
	int aLen, aW;
	unsigned int aClr, aTClr;
	aLen = 4;
	aW = aLen * 12 +12;
	
	if(WhatSel == 0){
		aClr = clBlue;
		aTClr = clBlue;
	}else{
		aClr = clGray;
		aTClr = clNearBlack;
	}
	
	VertLineRender(BoxBound.Left,		BoxBound.Top+12,		BoxBound.Height-12,	aClr);
	VertLineRender(BoxBound.Left+1,	BoxBound.Top+12,		BoxBound.Height-12,	aClr);
	VertLineRender(BoxBound.Right,	BoxBound.Top+12,		BoxBound.Height-12,	aClr);
	VertLineRender(BoxBound.Right-1,	BoxBound.Top+12,		BoxBound.Height-12,	aClr);
	
	HorizLineRender(BoxBound.Left, 	BoxBound.Top+12, 		6, 	aClr);
	HorizLineRender(BoxBound.Left, 	BoxBound.Top+12+1, 	6, 	aClr);
	HorizLineRender(BoxBound.Left, 	BoxBound.Bottom, 		BoxBound.Width, 	aClr);
	HorizLineRender(BoxBound.Left, 	BoxBound.Bottom -1, 	BoxBound.Width, 	aClr);
	
	HorizLineRender(BoxBound.Left + aW +6, 	BoxBound.Top+12, 		BoxBound.Width -6 -aW, 	aClr);
	HorizLineRender(BoxBound.Left + aW +6, 	BoxBound.Top+12+1, 	BoxBound.Width -6 -aW, 	aClr);
	
	char *tText;
	if(LanguageEnCn==0)tText="选定内容"; else tText="Selecte ";	
	TextRender_string24(BoxBound.Left + 8, BoxBound.Top, aTClr, clFrmFace, tText); 
}

void TPrintInf::DrawBoxItems(void)
{
	RectFillRender(BoxBound.Left, 	BoxBound.Top, BoxBound.Right, BoxBound.Bottom, clFrmFace);
	DrawBoxItemsOutLine();
	ReDrawItems();	
}

void TPrintInf::DrawBoxTimeOutLine()
{
	int aLen, aW;
	unsigned int aClr,aTClr;
	aLen = 4;
	aW = aLen * 12 +12;
	
	if(WhatSel == 1){
		aClr = clBlue;
		aTClr = clBlue;
	}else{
		aClr = clGray;
		aTClr = clNearBlack;
	}
	
	VertLineRender(BoxBoundTime.Left,	BoxBoundTime.Top+12,		BoxBoundTime.Height-12,	aClr);
	VertLineRender(BoxBoundTime.Left+1,	BoxBoundTime.Top+12,		BoxBoundTime.Height-12,	aClr);
	VertLineRender(BoxBoundTime.Right,	BoxBoundTime.Top+12,		BoxBoundTime.Height-12,	aClr);
	VertLineRender(BoxBoundTime.Right-1,BoxBoundTime.Top+12,		BoxBoundTime.Height-12,	aClr);
	
	HorizLineRender(BoxBoundTime.Left, 	BoxBoundTime.Top+12, 		6, 	aClr);
	HorizLineRender(BoxBoundTime.Left, 	BoxBoundTime.Top+12+1, 	6, 	aClr);
	HorizLineRender(BoxBoundTime.Left, 	BoxBoundTime.Bottom, 		BoxBoundTime.Width, 	aClr);
	HorizLineRender(BoxBoundTime.Left, 	BoxBoundTime.Bottom -1, 	BoxBoundTime.Width, 	aClr);
	
	HorizLineRender(BoxBoundTime.Left + aW +6, 	BoxBoundTime.Top+12, 		BoxBoundTime.Width -6 -aW, 	aClr);
	HorizLineRender(BoxBoundTime.Left + aW +6, 	BoxBoundTime.Top+12+1, 	BoxBoundTime.Width -6 -aW, 	aClr);
	
	if(LanguageEnCn==0)TextRender_string24(BoxBoundTime.Left + 8, BoxBoundTime.Top, aTClr, clFrmFace, "日期时间");
	else TextRender_string24(BoxBoundTime.Left + 8, BoxBoundTime.Top, aTClr, clFrmFace, "DateTime");
}

void TPrintInf::DrawTimeEntry(void)
{
	int x,y,w,h;
	int i;
	unsigned char aHex0, aHex1;
	
	w = 36;
	h = 32;
	
	vtValueFrom[0] = DateTime.Date.Split.Year;
	vtValueFrom[1] = DateTime.Date.Split.Month;
	vtValueFrom[2] = DateTime.Date.Split.Day;
	
	vtValueFrom[3] = DateTime.Time.Split.Hour;
	vtValueFrom[4] = DateTime.Time.Split.Minute;
	vtValueFrom[5] = DateTime.Time.Split.Second;
	
	vtValueTo[0] =vtValueFrom[0];
	vtValueTo[1] =vtValueFrom[1];
	vtValueTo[2] =vtValueFrom[2];
	vtValueTo[3] =vtValueFrom[3];
	vtValueTo[4] =vtValueFrom[4];
	vtValueTo[5] =vtValueFrom[5];
	
	
	for(i=0; i<6; i++){
		x = 438 + (i * 48);
		y = 210 + (0 * 112);
		
		aHex0 = vtValueFrom[i] / 16 % 10;
		aHex1 = vtValueFrom[i] % 16 % 10;
		vtTextFrom[i][0] = aHex0 + '0';
		vtTextFrom[i][1] = aHex1 + '0';
		vtTextFrom[i][2] = 0;
		RectFillRender(x, y, x+w-1, y+h-1, clFrmFace);
		TextRender_string24(x+3, y+3, clNearBlack, vtTextFrom[i]);
	}
	
	for(i=0; i<6; i++){
		x = 438 + (i * 48);
		y = 210 + (1 * 112);
		
		aHex0 = vtValueTo[i] / 16 % 10;
		aHex1 = vtValueTo[i] % 16 % 10;
		vtTextTo[i][0] = aHex0 + '0';
		vtTextTo[i][1] = aHex1 + '0';
		vtTextTo[i][2] = 0;
		RectFillRender(x, y, x+w-1, y+h-1, clFrmFace);
		TextRender_string24(x+3, y+3, clNearBlack, vtTextTo[i]);
	}
}

void TPrintInf::DrawTimeEntryNoUpdate(void)
{
	int x,y,w,h;
	int i;
	unsigned char aHex0, aHex1;
	
	w = 36;
	h = 32;
	
	for(i=0; i<6; i++){
		x = 438 + (i * 48);
		y = 210 + (0 * 112);
		
		//aHex0 = vtValueFrom[i] / 16 % 10;
		//aHex1 = vtValueFrom[i] % 16;
		//vtTextFrom[i][0] = aHex0 + '0';
		//vtTextFrom[i][1] = aHex1 + '0';
		vtTextFrom[i][2] = 0;
		RectFillRender(x, y, x+w-1, y+h-1, clFrmFace);
		TextRender_string24(x+3, y+3, clNearBlack, vtTextFrom[i]);
	}
	
	for(i=0; i<6; i++){
		x = 438 + (i * 48);
		y = 210 + (1 * 112);
		
		//aHex0 = vtValueTo[i] / 16 % 10;
		//aHex1 = vtValueTo[i] % 16;
		//vtTextTo[i][0] = aHex0 + '0';
		//vtTextTo[i][1] = aHex1 + '0';
		vtTextTo[i][2] = 0;
		RectFillRender(x, y, x+w-1, y+h-1, clFrmFace);
		TextRender_string24(x+3, y+3, clNearBlack, vtTextTo[i]);
	}
}

void TPrintInf::DrawBoxTime(void)
{
	unsigned int i;
	RectFillRender(BoxBoundTime.Left, 	BoxBoundTime.Top, BoxBoundTime.Right, BoxBoundTime.Bottom, clFrmFace);
	DrawBoxTimeOutLine();
	
	DrawTimeEntry();

}

void TPrintInf::DrawBoxTimeString(void)
{
	if(LanguageEnCn==0){
		TextRender_string24(BoxBoundTime.Left + 12, BoxBoundTime.Top + 34, clNearBlack, "开始时间");
		TextRender_string24(BoxBoundTime.Left + 42, BoxBoundTime.Top + 68, clNearBlack, "年  月  日  时  分  秒");
		TextRender_string24(BoxBoundTime.Left + 12, BoxBoundTime.Top + 147, clNearBlack, "结束时间");
		TextRender_string24(BoxBoundTime.Left + 42, BoxBoundTime.Top + 179, clNearBlack, "年  月  日  时  分  秒");
	}else{
		TextRender_string24(BoxBoundTime.Left + 12, BoxBoundTime.Top + 34, clNearBlack,  "Begin");
		TextRender_string24(BoxBoundTime.Left + 42, BoxBoundTime.Top + 68, clNearBlack,  " Y   M   D   H   M   S");
		TextRender_string24(BoxBoundTime.Left + 12, BoxBoundTime.Top + 147, clNearBlack, "End");
		TextRender_string24(BoxBoundTime.Left + 42, BoxBoundTime.Top + 179, clNearBlack, " Y   M   D   H   M   S");
	}
}

void TPrintInf::DrawSaveButton(void)
{
	unsigned int aClr, aTClr;
	int x,y,x2,y2;
	
	x = 590;
	y = 372;
	x2 = 736;
	y2 = 416;
	
	if(WhatSel == 2){
		aClr = clBlue;
		aTClr = clNearWhite;
	}else{
		aClr = clFrmFace;
		aTClr = clNearBlack;
	}
	
	RectFillRender(x, y, x2, y2, aClr);
	VertLineRender(x,		y, 		y2-y+1-1,	0xFFFFFFFF);
	VertLineRender(x2 -1,	y +1,		y2-y+1-2,	0xFF808080);
	VertLineRender(x2,	y,		y2-y+1-2,	0xFF404040);
	HorizLineRender(x, 	y, 		x2-x+1-1, 	0xFFFFFFFF);
	HorizLineRender(x +1, 	y2 -1,  	x2-x+1 - 2, 0xFF808080);
	HorizLineRender(x,	y2,		x2-x+1,	0xFF404040);
	
	if(LanguageEnCn==0)TextRender_string24(x + 28, y + 9, aTClr, "执行打印");
	else TextRender_string24(x + 28, y + 9, aTClr, 			 " Print  ");
}

void TPrintInf::ChangeWg(void)
{
	switch(FocusIndex){
		case 0: 	if(InfList[0]){
					InfList[0] = 0;
				}else{
					InfList[0] = 0xA5;
				}
				break;
		case 1: 	if(InfList[1]){
					InfList[1] = 0;
				}else{
					InfList[1] = 0xA5;
				}
				break;
		case 2: 	if(InfList[2]){
					InfList[2] = 0;
				}else{
					InfList[2] = 0xA5;
				}
				break;
		case 3: 	if(InfList[3]){
					InfList[3] = 0;
				}else{
					InfList[3] = 0xA5;
				}
				break;
		case 4: 	if(InfList[4]){
					InfList[4] = 0;
				}else{
					InfList[4] = 0xA5;
				}
				break;
	}					
}

void TPrintInf::SetEditStart(void)
{
	int x,y,w,h;
	
	IsEditing =1;
	ReStoreP0 = SelectedFromOrEnd;
	ReStoreP1 = SelectedIndex;
	
	x = 438 + (SelectedIndex * 48);
	y = 210 + (SelectedFromOrEnd * 112);
	w = 36;
	h = 32;
	
	vEdit.Init(x,y,w,h,0,0,1,clTeal);
	vEdit.Color = clTeal;
	vEdit.SetMaxLen(2);
	if(ReStoreP0 ==0){
		vEdit.Str.Text[0] = vtTextFrom[ReStoreP1][0];
		vEdit.Str.Text[1] = vtTextFrom[ReStoreP1][1];
		vEdit.Str.Text[2] = 0;
	}else
	if(ReStoreP0 ==1){
		vEdit.Str.Text[0] = vtTextTo[ReStoreP1][0];
		vEdit.Str.Text[1] = vtTextTo[ReStoreP1][1];
		vEdit.Str.Text[2] = 0;
	}
	vEdit.SetPstTail();
	vEdit.Show();
	vEdit.ShowCursor(clNearWhite);
}

void TPrintInf::RestoreFromEdit(void)
{
	int x,y,w,h;
	
	if(IsEditing == 0)return;
	
	x = 438 + (SelectedIndex * 48);
	y = 210 + (ReStoreP0 * 112);
	w = 36;
	h = 32;
	
	RectFillRender(x, y, x+w-1, y+h-1, clFrmFace);
	if(ReStoreP0 == 0){
		vtTextFrom[ReStoreP1][0] = vEdit.Str.Text[0];
		vtTextFrom[ReStoreP1][1] = vEdit.Str.Text[1];
		vtTextFrom[ReStoreP1][2] = 0;
		TextRender_string24(x+3, y+3, clNearBlack, vtTextFrom[ReStoreP1]);
	}else
	if(ReStoreP0 == 1){
		vtTextTo[ReStoreP1][0] = vEdit.Str.Text[0];
		vtTextTo[ReStoreP1][1] = vEdit.Str.Text[1];
		vtTextTo[ReStoreP1][2] = 0;
		TextRender_string24(x+3, y+3, clNearBlack, vtTextTo[ReStoreP1]);
	}
	IsEditing = 0;
}

TGuiMsgReturn TPrintInf::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	TGuiMsgReturn PmsRtnMsg;
	int isMaskReturn = 0;
	if(IsPermission){
		PmsRtnMsg = PmsIntervene4Gui.KeyIn(aKey);
		if(PmsRtnMsg == guiMsgOkAndReturn){
			//Enter And Run Go
			IsPermission = 0;
			PermissionCmdReturnDraw();
			PermissionCmdGO();
		}else
		if(PmsRtnMsg == guiMsgReturn){
			//Not Enter Redraw
			IsPermission = 0;
			PermissionCmdReturnDraw();
		}
		return aMsg;
	}else
	if(WhatSel == 0){
		if( (aKey == VK_EXECUTE) || (aKey == dfKEY_SETUP) ){
			ChangeWg();
			DrawWidget();
		}else
		if( aKey == VK_RIGHT){
			WhatSel = 1;
			DrawBoxItemsOutLine();
			DrawBoxTimeOutLine();
			DrawSaveButton();
			if(WhatSel == 1){
				if(IsEditing == 0){
					SetEditStart();
				}
			}else{
				if(IsEditing){
					RestoreFromEdit();
				}
			}
		}else
		if(aKey == VK_UP){
			if(FocusIndex >0){
				FocusIndex--;
				DrawWidget();
			}
		}else
		if(aKey == VK_DOWN){
			if(FocusIndex <4){
				FocusIndex++;
				DrawWidget();
			}
		}
	}else
	if(WhatSel == 1){
		if(aKey == VK_LEFT){
			if(SelectedIndex >0){
				RestoreFromEdit();
				SelectedIndex--;
				SetEditStart();
			}
		}else
		if(aKey == VK_RIGHT){
			if(SelectedIndex <5){
				RestoreFromEdit();
				SelectedIndex++;
				SetEditStart();
			}
		}else
		if(aKey == VK_UP){
			if(SelectedFromOrEnd >0){
				RestoreFromEdit();
				SelectedFromOrEnd--;
				SetEditStart();
			}
		}else
		if(aKey == VK_DOWN){
			if(SelectedFromOrEnd <1){
				RestoreFromEdit();
				SelectedFromOrEnd++;
				SetEditStart();
			}else{
				WhatSel = 2;
				DrawBoxItemsOutLine();
				DrawBoxTimeOutLine();
				DrawSaveButton();
				if(WhatSel == 1){
					if(IsEditing == 0){
						SetEditStart();
					}
				}else{
					if(IsEditing){
						RestoreFromEdit();
					}
				}
			}
		}else{
			switch(aKey){
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9':
				case VK_DELETE:
					vEdit.KeyIn(aKey);
					vEdit.Show();
					vEdit.ShowCursor(clNearWhite);
				break;
			}
		}
	}else
	if(WhatSel == 2){
		if(aKey == VK_EXECUTE){
			//Get Detial Here
			WhatSel = 3;
			GetDetial();
			ShowDetial();
		}else
		if(aKey == VK_UP){
			WhatSel = 1;
			DrawBoxItemsOutLine();
			DrawBoxTimeOutLine();
			DrawSaveButton();
			if(WhatSel == 1){
				if(IsEditing == 0){
					SetEditStart();
				}
			}else{
				if(IsEditing){
					RestoreFromEdit();
				}
			}
		}
	}else
	if(WhatSel == 3){
		if(aKey == VK_EXECUTE){
			//Print Here
			if(SystemPermission > 1){
				PermissionCmdGO();
			}else{
				IsPermission = 1;
				PmsIntervene4Gui.Show4Gui(200, 86, 400, 140, 2);
			}
		}else
		if(aKey == VK_RETURN){
			isMaskReturn = 1;
			WhatSel = 2;
			RectFillRender(Content.Left, Content.Top, Content.Right, Content.Bottom, clFrmFace);
			DrawBoxItems();
			ReDrawItems();
			DrawWidget();
			DrawBoxTimeOutLine();
			DrawTimeEntryNoUpdate();
			DrawBoxTimeString();
			DrawSaveButton();
		}
	}else{
		WhatSel = 0;
	}
	
	if(aKey == VK_TAB){
		WhatSel++;
		if(WhatSel >2)WhatSel = 0;
		DrawBoxItemsOutLine();
		DrawBoxTimeOutLine();
		DrawSaveButton();
		if(WhatSel == 1){
			if(IsEditing == 0){
				SetEditStart();
			}
		}else{
			if(IsEditing){
				RestoreFromEdit();
			}
		}
	}else
	if(aKey == VK_RETURN){
		if(isMaskReturn == 0){
			aMsg = guiMsgReturn;
		}
	}
	return aMsg;
}

void TPrintInf::GetDetial()
{
	GetStartStopTime();
	pMsg->LoadData();
	pMsg->StartTime = this->StartTime;
	pMsg->StopTime = this->StopTime;
	pMsg->FindInTimeEntry();
	
	this->Count = pMsg->Count;
	this->CountFire = pMsg->CountFire;
	this->CountLinkage = pMsg->CountLinkage;
	this->CountSv = pMsg->CountSv;
	this->CountFault = pMsg->CountFault;
	this->CountOperate = pMsg->CountOperate;
	
	this->Count2Print =0;
	this->Count2Print += InfList[0] ? this->CountFire : 0;
	this->Count2Print += InfList[1] ? this->CountLinkage : 0;
	this->Count2Print += InfList[2] ? this->CountSv : 0;
	this->Count2Print += InfList[3] ? this->CountFault : 0;
	this->Count2Print += InfList[4] ? this->CountOperate : 0;
	
	this->InxScope.Begin.Fire 	= pMsg->InxScope.Begin.Fire;
	this->InxScope.End.Fire		= pMsg->InxScope.End.Fire;
	this->InxScope.Begin.Lnk 	= pMsg->InxScope.Begin.Lnk;
	this->InxScope.End.Lnk 		= pMsg->InxScope.End.Lnk;
	this->InxScope.Begin.Sv 	= pMsg->InxScope.Begin.Sv;
	this->InxScope.End.Sv 		= pMsg->InxScope.End.Sv;
	this->InxScope.Begin.Fault 	= pMsg->InxScope.Begin.Fault;
	this->InxScope.End.Fault 	= pMsg->InxScope.End.Fault;
	this->InxScope.Begin.Opa 	= pMsg->InxScope.Begin.Opa;
	this->InxScope.End.Opa 		= pMsg->InxScope.End.Opa;
}


unsigned long long TPrintInf::GetMsgMemInx(int What, int aInx)
{
	unsigned int Addr, SdAddr;
	TDMix64 tMemInx;
	tMemInx.D64 =0;
	if(What == 0){
			Addr = Record.Buf4Fire.SdramAddrStart + aInx * 64;
			if(Addr >= (dSdramFireHistoryContentBaseAddr + dSdramHistoryBytesLength) )
				SdAddr = Addr - dSdramHistoryBytesLength;
			else
				SdAddr = Addr;
			tMemInx.D32[0] = *(volatile unsigned int *)(SdAddr + 0);
			tMemInx.D32[1] = *(volatile unsigned int *)(SdAddr + 4);
	}else
	if(What == 1){
			Addr = Record.Buf4Linkage.SdramAddrStart + aInx * 64;
			if(Addr >= (dSdramLinkageHistoryContentBaseAddr + dSdramHistoryBytesLength) )
				SdAddr = Addr - dSdramHistoryBytesLength;
			else
				SdAddr = Addr;
			tMemInx.D32[0] = *(volatile unsigned int *)(SdAddr + 0);
			tMemInx.D32[1] = *(volatile unsigned int *)(SdAddr + 4);
	}else
	if(What == 2){
			Addr = Record.Buf4Sv.SdramAddrStart + aInx * 64;
			if(Addr >= (dSdramSvHistoryContentBaseAddr + dSdramHistoryBytesLength) )
				SdAddr = Addr - dSdramHistoryBytesLength;
			else
				SdAddr = Addr;
			tMemInx.D32[0] = *(volatile unsigned int *)(SdAddr + 0);
			tMemInx.D32[1] = *(volatile unsigned int *)(SdAddr + 4);
	}else
	if(What == 3){
			Addr = Record.Buf4Fault.SdramAddrStart + aInx * 64;
			if(Addr >= (dSdramFaultHistoryContentBaseAddr + dSdramHistoryBytesLength) )
				SdAddr = Addr - dSdramHistoryBytesLength;
			else
				SdAddr = Addr;
			tMemInx.D32[0] = *(volatile unsigned int *)(SdAddr + 0);
			tMemInx.D32[1] = *(volatile unsigned int *)(SdAddr + 4);
	}else
	if(What == 4){
			Addr = Record.Buf4Operate.SdramAddrStart + aInx * 64;
			if(Addr >= (dSdramOperateHistoryContentBaseAddr + dSdramHistoryBytesLength) )
				SdAddr = Addr - dSdramHistoryBytesLength;
			else
				SdAddr = Addr;
			tMemInx.D32[0] = *(volatile unsigned int *)(SdAddr + 0);
			tMemInx.D32[1] = *(volatile unsigned int *)(SdAddr + 4);
	}
	return tMemInx.D64;
}

int TPrintInf::PrintOneEntry()
{
	int i, WhatMax, tInx;
	unsigned long long tMx;
	tMx =0;
	int tDoneCount =0;
	WhatMax = -1;
	for(i=0; i<5; i++){
		if(InfList[i]){
			OnGo.MemX[i] = GetMsgMemInx(i,OnGo.Inx[i]);
		}
	}
	for(i=0; i<5; i++){
		if(InfList[i]){
			if(OnGo.MemX[i] > tMx){
				tMx = OnGo.MemX[i];
				tInx = OnGo.Inx[i];
				WhatMax = i;
			}
		}
	}
	
	if(WhatMax <0)return 1;

	if( (WhatMax > -1) && (WhatMax < 5) ){
		if(WhatMax == 0){
			pMsg->MsgFire->GetEntry4Print(tInx);
			RecordMsg.D32[0] = pMsg->MsgFire->EntryTmp.fData.Body.D32[0];
			RecordMsg.D32[1] = pMsg->MsgFire->EntryTmp.fData.Body.D32[1];
			RecordMsg.D32[2] = pMsg->MsgFire->EntryTmp.fData.Body.D32[2];
			RecordMsg.D32[3] = pMsg->MsgFire->EntryTmp.fData.Body.D32[3];
			RecordMsg.Splite.UserCode = pMsg->MsgFire->EntryTmp.fData.UserCode;
			DoPrint.PrintHistory(0, RecordMsg, &pMsg->MsgFire->Text.Text[24]);
		}else
		if(WhatMax == 1){
			pMsg->MsgLinkage->GetEntry4Print(tInx);
			RecordMsg.D32[0] = pMsg->MsgLinkage->EntryTmp.fData.Body.D32[0];
			RecordMsg.D32[1] = pMsg->MsgLinkage->EntryTmp.fData.Body.D32[1];
			RecordMsg.D32[2] = pMsg->MsgLinkage->EntryTmp.fData.Body.D32[2];
			RecordMsg.D32[3] = pMsg->MsgLinkage->EntryTmp.fData.Body.D32[3];
			RecordMsg.Splite.UserCode = pMsg->MsgLinkage->EntryTmp.fData.UserCode;
			DoPrint.PrintHistory(1, RecordMsg, &pMsg->MsgLinkage->Text.Text[24]);
		}else
		if(WhatMax == 2){
			pMsg->MsgSv->GetEntry4Print(tInx);
			RecordMsg.D32[0] = pMsg->MsgSv->EntryTmp.fData.Body.D32[0];
			RecordMsg.D32[1] = pMsg->MsgSv->EntryTmp.fData.Body.D32[1];
			RecordMsg.D32[2] = pMsg->MsgSv->EntryTmp.fData.Body.D32[2];
			RecordMsg.D32[3] = pMsg->MsgSv->EntryTmp.fData.Body.D32[3];
			RecordMsg.Splite.UserCode = pMsg->MsgSv->EntryTmp.fData.UserCode;
			DoPrint.PrintHistory(2, RecordMsg, &pMsg->MsgSv->Text.Text[24]);
		}else
		if(WhatMax == 3){
			pMsg->MsgFault->GetEntry4Print(tInx);
			RecordMsg.D32[0] = pMsg->MsgFault->EntryTmp.fData.Body.D32[0];
			RecordMsg.D32[1] = pMsg->MsgFault->EntryTmp.fData.Body.D32[1];
			RecordMsg.D32[2] = pMsg->MsgFault->EntryTmp.fData.Body.D32[2];
			RecordMsg.D32[3] = pMsg->MsgFault->EntryTmp.fData.Body.D32[3];
			RecordMsg.Splite.UserCode = pMsg->MsgFault->EntryTmp.fData.UserCode;
			DoPrint.PrintHistory(3, RecordMsg, &pMsg->MsgFault->DescpText.Text[28]);
		}else
		if(WhatMax == 4){
			pMsg->MsgOperate->GetEntry4Print(tInx);
			RecordMsg.D32[0] = pMsg->MsgOperate->EntryTmp.fData.Body.D32[0];
			RecordMsg.D32[1] = pMsg->MsgOperate->EntryTmp.fData.Body.D32[1];
			RecordMsg.D32[2] = pMsg->MsgOperate->EntryTmp.fData.Body.D32[2];
			RecordMsg.D32[3] = pMsg->MsgOperate->EntryTmp.fData.Body.D32[3];
			RecordMsg.Splite.UserCode = pMsg->MsgOperate->EntryTmp.fData.UserCode;
			DoPrint.PrintHistory(4, RecordMsg, &pMsg->MsgOperate->Text.Text[28]);
		}
		OnGo.Inx[WhatMax]--;
	}
	if(InfList[0] && (OnGo.Inx[0] < InxScope.Begin.Fire) ){
		tDoneCount++;
	}
	if(InfList[1] && (OnGo.Inx[1] < InxScope.Begin.Lnk) ){
		tDoneCount++;
	}
	if(InfList[2] && (OnGo.Inx[2] < InxScope.Begin.Sv) ){
		tDoneCount++;
	}
	if(InfList[3] && (OnGo.Inx[3] < InxScope.Begin.Fault) ){
		tDoneCount++;
	}
	if(InfList[4] && (OnGo.Inx[4] < InxScope.Begin.Opa) ){
		tDoneCount++;
	}
	if(tDoneCount >= OnGo.AvaCount)return 1;
	return 0;
}

void TPrintInf::GoPrint()
{
	int i;
	int MaxCount = PrintBuf_Count /2;
	OnGo.Init();
	OnGo.Inx[0] = this->InxScope.End.Fire;
	OnGo.Inx[1] = this->InxScope.End.Lnk;
	OnGo.Inx[2] = this->InxScope.End.Sv;
	OnGo.Inx[3] = this->InxScope.End.Fault;
	OnGo.Inx[4] = this->InxScope.End.Opa;
	
	for(i=0;i<5;i++){
		if(InfList[i])
			OnGo.AvaCount++;
	}
	
	for(OnGo.px=0, i=0; (OnGo.px<MaxCount) && (i<Count2Print) ; OnGo.px++, i++){
		if(PrintOneEntry())break;
	}
}






