#include "gType.h"
#include "GraphLow.h"
#include "GraphBase.h"
#include "GlobalString.h"
#include "RuntimeData.h"
#include "Runtime.h"
#include "Gui.h"
#include "DevCount.h"

#define TextTopOffSet	6
#define ListLineCnt	10
#define IconVcnt	5
#define IconHcnt	10

#define HLineTextRight	780
#define HSpace	33

#define clOdd	clMoneyGreen
#define clEven	clWhiteBlue

#define dCountDrawX	60
#define dCountDrawY	120

#define dCountDrawWidth		640
#define dCountDrawHeight	320

#define dPortInxMax	24

static const int Lv0Left[5] ={
	10, 130, 280, 460, 610
};
static const int Lv1Left[6] ={
	4, 64, 164, 230, 340, 410
};

void TDevCount::DrawFixText()
{
	volatile int aCn;
	if(LanguageEnCn==0){	
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite, CaptionColor, "回路->注册类型数量查看             ");
		TextRender_string24(Lv0Left[0],Lv.Grid.Top[1] + 4, clNearWhite, "回路");
		TextRender_string24(Lv0Left[1],Lv.Grid.Top[1] + 4, clNearWhite, "已注册点数");
		TextRender_string24(Lv0Left[2],Lv.Grid.Top[1] + 4, clNearWhite, "未注册点数");
		TextRender_string24(Lv0Left[3],Lv.Grid.Top[1] + 4, clNearWhite, "屏蔽地址数");
		TextRender_string24(Lv0Left[4],Lv.Grid.Top[1] + 4, clNearWhite, "已注册比例");
	
		TMyString::sClear(Text);
		TMyString::sFromStr("机器号 ", Text);
		TMyString::sAddOn2Dg(MainCtl.fData.Split.MyNum,Text);
		TMyString::sAddOnStr(" 本机", Text);
		TextRender_string24(Lv.Grid.Left[ 0]+ 10, Lv.Grid.Top[ 0]+ 4, clNearWhite, Text);
	
		TMyString::sClear(Text);
		TMyString::sFromStr("总回路数", Text);
		TMyString::sAddOn2Dg(MainCtl.fData.Split.PortCount,Text);
		TMyString::sAddOnStr("  已注册总点数",Text);
	}else{
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite, CaptionColor, "Loop->Amount Of Different Types   ");
		TextRender_string24(Lv0Left[0],Lv.Grid.Top[1] + 4, clNearWhite, "Loop");
		TextRender_string24(Lv0Left[1],Lv.Grid.Top[1] + 4, clNearWhite, "Registered");
		TextRender_string24(Lv0Left[2],Lv.Grid.Top[1] + 4, clNearWhite, "UnRegister");
		TextRender_string24(Lv0Left[3],Lv.Grid.Top[1] + 4, clNearWhite, "Blockings");
		TextRender_string24(Lv0Left[4],Lv.Grid.Top[1] + 4, clNearWhite, "Reg Ratio");
	
		TMyString::sClear(Text);
		TMyString::sFromStr("CtlID ", Text);
		TMyString::sAddOn2Dg(MainCtl.fData.Split.MyNum,Text);
		TMyString::sAddOnStr(" Local", Text);
		TextRender_string24(Lv.Grid.Left[ 0]+ 10, Lv.Grid.Top[ 0]+ 4, clNearWhite, Text);
	
		TMyString::sClear(Text);
		TMyString::sFromStr("Loop(s)", Text);
		TMyString::sAddOn2Dg(MainCtl.fData.Split.PortCount,Text);
		TMyString::sAddOnStr("  Amout Of Registered:",Text);		
	}
	aCn =0;
	for(int i=0; i<dPortInxMax; i++){
		if(MainCtl.fData.Split.ExistTablePort[i] == 0xA5){
			for(int x=0; x<dEP_MAX_COUNT_PER_PORT; x++){
				if( (Port[i].ExistTable[x] == 0xA5) && (Port[i].dTypeTable[x] != 0) ){
					aCn++;
				}
			}
		}
	}
	TMyString::sAddOn5Dg(aCn,Text);
	TextRender_string24(Lv.Grid.Left[ 0]+ 320, Lv.Grid.Top[ 0]+ 4, clNearWhite, ItemColor, Text);
}

void TDevCount::Init()
{
	IsShow = 0;
	
	PortInx =0;
	PortInxTop =0;
	Line =0;
	IsShowingCount =0;
	HasDraw4P0 =0;
}

void TDevCount::RenderBackGround(void)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, ContentColor);
}

void TDevCount::RenderBackGround(unsigned int aClr)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, aClr);
}

void TDevCount::Show(void)
{
	DrawSelf();
	DrawList();	
	Check4SelectedLv0();
	IsShow = 1;
}

void TDevCount::FullRedraw(int Prm)
{
	if(Prm == 0){
		RenderBackGround();
		DrawSelf();
		DrawList();
		Check4SelectedLv0();
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
		if(IsShowingCount){
			RenderBackGround();
			DrawPortDevCount(PortInx);
		}else{
			RenderBackGround();
			DrawSelf();
			DrawList();
			Check4SelectedLv0();
		}
	}
}

void TDevCount::DrawSelf(void)
{
	RenderBackGround();
	RectFillRender(Lv.Caption.Left, Lv.Caption.Top, Lv.Caption.Right, Lv.Caption.Bottom, CaptionColor);
	
	for(int i=0; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	
	DrawFixText();
	
}

void TDevCount::DrawList(void)
{
	int i,t,x,y;
	unsigned int tAddr;
	unsigned int ExistCnt, cnt, aP0, tClr, tPR;
	
	if(IsShowingCount == 0){
		for(i=0, t=PortInxTop; i<8; i++, t++){
			if(t){
				if(t<=dPortInxMax){
					aP0 = t -1;
					if(MainCtl.fData.Split.ExistTablePort[aP0] == 0xA5){
						tClr = clNearWhite;
						tPR =1;
					}else{
						tClr = clSilver;
						tPR =0;
					}
					//Draw Port Num
					if(LanguageEnCn==0)TextRender_string24(Lv0Left[0],Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "回路    ");
					else TextRender_string24(Lv0Left[0],Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "Loop    ");
					TextDigitRender2_24(Lv0Left[0]+48, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, aP0+1);
					if(tPR){
						//Draw Registed 
						ExistCnt = 0;
						for(x=0; x<250; x++){
							if( (Port[aP0].ExistTable[x] == 0xA5) && Port[aP0].dTypeTable[x])ExistCnt++;
						}
						//override Register
						TextRender_string24(Lv0Left[1] + 36, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "     ");
						TextDigitRender3_24(Lv0Left[1] + 60, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, ExistCnt);
						
						//override Unregister
						TextRender_string24(Lv0Left[2] + 0, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "     ");
						//Draw UnRegisted
						TextDigitRender3_24(Lv0Left[2] + 24, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, 250 - ExistCnt);
						
						
						//override Mask
						TextRender_string24(Lv0Left[3] +36, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "      ");
						//Draw Mask
						cnt =0;
						for(x=0; x<250; x++){
							if(Port[aP0].StateTable[x] & dEpStateBitMask)cnt++;
						}
						TextDigitRender3_24(Lv0Left[3] + 60, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, cnt);
						//Draw Percent
						cnt = ExistCnt * 1000 / 250;
						TextDigitRender3_24(Lv0Left[4], Lv.Grid.Top[i+2] + 4, tClr, ItemColor, cnt/10);
						TextRender_string24(Lv0Left[4]+36, Lv.Grid.Top[i+2] + 4, tClr, "." );
						TextDigitRender1Right24(Lv0Left[4]+48, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, cnt%10);
						TextRender_string24(Lv0Left[4]+62, Lv.Grid.Top[i+2] + 4, tClr, "%" );
					}else{
						//override register
						TextRender_string24(Lv0Left[1] + 36, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "      ");
						//override Unregister
						TextRender_string24(Lv0Left[2], Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "     ");
						//override Mask
						TextRender_string24(Lv0Left[3] +36, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "      ");
						//override Percent
						TextRender_string24(Lv0Left[4], Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "       ");
					}
				}else{
					//override register
					TextRender_string24(Lv0Left[1] + 36, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "      ");
					//override Unregister
					TextRender_string24(Lv0Left[2], Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "     ");
					//override Mask
					TextRender_string24(Lv0Left[3] +36, Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "      ");
					//override Percent
					TextRender_string24(Lv0Left[4], Lv.Grid.Top[i+2] + 4, tClr, ItemColor, "       ");
				}
			}else{
				if(LanguageEnCn==0)TextRender_string24(Lv0Left[0],Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, "全部回路");
				else TextRender_string24(Lv0Left[0],Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, "Loops");
				//Draw Registed 
				ExistCnt =0;
				for(int z=0; z<dPortInxMax; z++){
					if(MainCtl.fData.Split.ExistTablePort[z] == 0xA5){
						for(int x=0; x<dEP_MAX_COUNT_PER_PORT; x++){
							if( (Port[z].ExistTable[x] == 0xA5) && (Port[z].dTypeTable[x] != 0) ){
								ExistCnt++;
							}
						}
					}
				}
				TextDigitRender5_24(Lv0Left[1] + 36, Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, ExistCnt % 100000);
				//override Unregister
				TextRender_string24(Lv0Left[2], Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, "     ");
				int tTC = 0;
				for(int ig=0; ig<dPortInxMax; ig++){
					if(MainCtl.fData.Split.ExistTablePort[ig] == 0xA5){
						tTC += dEP_MAX_COUNT_PER_PORT;
					}
				}
				//Draw UnRegisted
				TextDigitRender5_24(Lv0Left[2], Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, (tTC - ExistCnt)%100000);
				
				//Draw Mask
				cnt =0;
				for(int z=0; z<dPortInxMax; z++){
					if(MainCtl.fData.Split.ExistTablePort[z] == 0xA5){
						for(x=0; x<250; x++){
							if(Port[z].StateTable[x] & dEpStateBitMask)cnt++;
						}
					}
				}
				TextDigitRender5_24(Lv0Left[3] +36, Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, cnt % 100000);
				
				//override Percent
				TextRender_string24(Lv0Left[4], Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, "       ");
				cnt = ExistCnt * 1000 / tTC;
				TextDigitRender3_24(Lv0Left[4], Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, cnt/10);
				TextRender_string24(Lv0Left[4]+36, Lv.Grid.Top[i+2] + 4, clNearWhite, "." );
				TextDigitRender1Right24(Lv0Left[4]+48, Lv.Grid.Top[i+2] + 4, clNearWhite, ItemColor, cnt%10);
				TextRender_string24(Lv0Left[4]+62, Lv.Grid.Top[i+2] + 4, clNearWhite, "%" );
			}
		}
	}
}

void TDevCount::GetOnePortCount(unsigned char aP0)
{
	if(aP0 == 0)return;
	if(aP0 >dPORT_MAX_COUNT)return;
	
	unsigned char tP0 = aP0-1;
	if(MainCtl.fData.Split.ExistTablePort[tP0] == 0xA5){
		for(int j=0; j<250; j++){
			if(Port[tP0].ExistTable[j]){
				unsigned char aType = Port[tP0].dTypeTable[j];
				if(aType){
					if(  (aType == dgTYPE_SMOKE_DETECTOR)  ){
						     Count.Smoke++;
					}else
					if(  aType ==  dgTYPE_TEMPE_DETECTOR ){
						     Count.Tempe++;
					}else
					if(  (aType == dgTYPE_HAND_REPORT ) ){
						     Count.HandReport++;
					}else
					if(  (aType == dgTYPE_FIRE_HydrantKp ) ){
						     Count.HydKp++;
					}else
					if(  (aType == dgTYPE_IN_MODULE ) ){
						     Count.ModuleInput++;
					}else
					if(   (aType == dgTYPE_INOUT_MODULE_NonSource) ||
						(aType == dgTYPE_INOUT_MODULE_Source) ){
						     Count.ModuleInOut++;
					}else
					if(  (aType == dgTYPE_OUT_MODULE) ){
						     Count.ModuleOutput++;
					}else
					if(  (aType == dgType_VAALRAM )  ){
						     Count.Va++;
					}else
					if(  aType == dgTYPE_DISPLAY_PAD ){
						     Count.FDisplay++;
					}else
					if(  aType == dgTYPE_LINKAGE_POWERSUPLY ){
						     Count.LinkPwr++;
					}else
					if(  aType == dgTYPE_SMOKE_TEMPE_DETECTOR ){
						     Count.SmokeTempe++;
					}else{
						Count.cOther++;
					}
				}
			}
		}
	}
}

void TDevCount::DrawPortDevCount()
{
	int x, yOffset;
	unsigned char tP0;
	
	if(HasDraw4P0 > dPORT_MAX_COUNT)return;
	RectFillRender(0, Lv.Grid.Top[1] -1, 800 -1, 440 -1, ContentColor);
	RectFillRender(dCountDrawX, dCountDrawY, dCountDrawX + dCountDrawWidth -1, dCountDrawY + (7 * 32)-1, clMoneyGreen);
	
	x = (7 * 32)-1;
	VertLineRender(dCountDrawX + 0,				dCountDrawY, 	x,	clBlue);
	VertLineRender(dCountDrawX + 190,				dCountDrawY, 	x,	clBlue);
	VertLineRender(dCountDrawX + 320,				dCountDrawY, 	x,	clBlue);
	VertLineRender(dCountDrawX + 510,				dCountDrawY, 	x,	clBlue);
	VertLineRender(dCountDrawX + dCountDrawWidth -1,	dCountDrawY, 	x,	clBlue);
	
	for(x=0; x<8;x++){
		HorizLineRender(dCountDrawX,	dCountDrawY + (x * 32), dCountDrawWidth -1,	clBlue);
	}
	
	Count.Reset();
	if(HasDraw4P0){
		GetOnePortCount(HasDraw4P0);
	}else{
		for(int i=0; i<dPortInxMax; i++){
			GetOnePortCount(i+1);
		}
	}
	yOffset = 4;
	x =0;
	if(LanguageEnCn==0){
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 0*32 , clNearBlack, "烟感:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 1*32 , clNearBlack, "温感:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 2*32 , clNearBlack, "输入模块:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 3*32 , clNearBlack, "输出模块:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 4*32 , clNearBlack, "手报:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 5*32 , clNearBlack, "消钮:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 6*32 , clNearBlack, "输入输出模块:" );
		
		x =320 + 4;
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 0*32 , clNearBlack, "层显:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 1*32 , clNearBlack, "声光警报器:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 2*32 , clNearBlack, "联动电源:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 3*32 , clNearBlack, "烟感+温感:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 4*32 , clNearBlack, "其他:" );
	}else{
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 0*32 , clNearBlack, "Smoke Det:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 1*32 , clNearBlack, "Tempe Det:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 2*32 , clNearBlack, "MDL Input:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 3*32 , clNearBlack, "Output:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 4*32 , clNearBlack, "Hand Report:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 5*32 , clNearBlack, "Hydrant:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 6*32 , clNearBlack, "MDL In&Out:" );
		
		x =320 + 4;
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 0*32 , clNearBlack, "Display Pad:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 1*32 , clNearBlack, "Acoustooptic:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 2*32 , clNearBlack, "Power Link:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 3*32 , clNearBlack, "Smoke & Tempe:" );
		TextRender_string24(dCountDrawX+20 +x, dCountDrawY+yOffset + 4*32 , clNearBlack, "Others:" );
	}
	
	x =0;
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 0*32 ,clNearBlack, Count.Smoke);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 1*32 ,clNearBlack, Count.Tempe);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 2*32 ,clNearBlack, Count.ModuleInput);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 3*32 ,clNearBlack, Count.ModuleOutput);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 4*32 ,clNearBlack, Count.HandReport);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 5*32 ,clNearBlack, Count.HydKp);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 6*32 ,clNearBlack, Count.ModuleInOut);
	
	x =320 + 4;
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 0*32 ,clNearBlack, Count.FDisplay);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 1*32 ,clNearBlack, Count.Va);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 2*32 ,clNearBlack, Count.LinkPwr);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 3*32 ,clNearBlack, Count.SmokeTempe);
	TextDigitRender5Right24(dCountDrawX+200 +x, dCountDrawY+yOffset + 4*32 ,clNearBlack, Count.cOther);
}


void TDevCount::DrawPortDevCount(unsigned char aP0)
{
	int x;
	unsigned char tP0;
	if(aP0 > dPORT_MAX_COUNT)return;
	HasDraw4P0 = aP0;
	DrawPortDevCount();
}

void TDevCount::ClearSelectedLv0(void)
{
	int iT;
	iT = Line + 2;
	if(iT > 9)return;
	RectFillRender(Lv.Grid.Left[iT],  Lv.Grid.Top[iT],  Lv.Grid.Left[iT] + Lv.Grid.Right[iT],  Lv.Grid.Top[iT] + 3,  ItemColor);   //draw rectangle
	RectFillRender(Lv.Grid.Left[iT],  Lv.Grid.Top[iT],  Lv.Grid.Left[iT] + 3,  Lv.Grid.Bottom[iT],  ItemColor);   //draw rectangle
	RectFillRender(Lv.Grid.Right[iT] -3,  Lv.Grid.Top[iT],  Lv.Grid.Right[iT],  Lv.Grid.Bottom[iT],  ItemColor);   //draw rectangle
	RectFillRender(Lv.Grid.Left[iT],  Lv.Grid.Bottom[iT] -3,  Lv.Grid.Right[iT],  Lv.Grid.Bottom[iT],  ItemColor);   //draw rectangle
}

void TDevCount::Check4SelectedLv0(void)
{
	int iT;
	iT = Line + 2;
	if(iT > 9)return;
	RectFillRender(Lv.Grid.Left[iT],  Lv.Grid.Top[iT],  Lv.Grid.Left[iT] + Lv.Grid.Right[iT],  Lv.Grid.Top[iT] + 3,  clBlue);   //draw rectangle
	RectFillRender(Lv.Grid.Left[iT],  Lv.Grid.Top[iT],  Lv.Grid.Left[iT] + 3,  Lv.Grid.Bottom[iT],  clBlue);   //draw rectangle
	RectFillRender(Lv.Grid.Right[iT] -3,  Lv.Grid.Top[iT],  Lv.Grid.Right[iT],  Lv.Grid.Bottom[iT],  clBlue);   //draw rectangle
	RectFillRender(Lv.Grid.Left[iT],  Lv.Grid.Bottom[iT] -3,  Lv.Grid.Right[iT],  Lv.Grid.Bottom[iT],  clBlue);   //draw rectangle
}

TGuiMsgReturn TDevCount::KeyIn(unsigned char aKey)
{
	int ind,i,aIndex, Found;
	unsigned char aP0;
	TGuiMsgReturn aMsg = guiMsgNone;
	TGuiMsgReturn aMsg2Rtn = guiMsgNone;
	//Up or Down One Index___________________
	
	if(IsShowingCount == 0){
		if(VK_LEFT ==aKey){
						
		}else
		if(VK_RIGHT == aKey){

		}else
		if(VK_UP == aKey){
			if(Line >0){
				ClearSelectedLv0();
				Line--;
				PortInx--; 
				Check4SelectedLv0();
			}else{
				if(PortInx >0){
					PortInx--;
					PortInxTop = PortInx; 
					DrawList();
				}
			}
		}else
		if(VK_DOWN == aKey){
			if(Line < 7){
				if(PortInx < dPortInxMax){
					ClearSelectedLv0();
					Line++;
					PortInx++; 
					Check4SelectedLv0();
				}
			}else{
				Line = 7;
				if(PortInx < dPortInxMax){
					PortInx++; 
					PortInxTop++; 
					DrawList();
				}
			}
		}else
		if(aKey == VK_TAB){

		}else
		if(aKey == VK_EXECUTE){
			//Open path Device
			IsShowingCount =1;
			DrawPortDevCount(PortInx);
		}else
		if(aKey == VK_RETURN){
			aMsg = guiMsgReturn;
		}else{

		}
	}else{
		if(aKey == VK_RETURN){
			IsShowingCount =0;
			RenderBackGround();
			DrawSelf();
			DrawList();
			Check4SelectedLv0();
		}else{
			
		}
	}

	//____________________________________________________________________<- List View

	return aMsg;

}

		









