#include "Gui.h"
#include "DevProperty.h"

extern "C"{
	#include "user_norflash.h"
	#include "user_eeprom.h"
	#include "uart_key_drv.h"
}

#define dWdClr		clSkyBlue
#define dWdDisabelClr	clNearWhite

#define dWWidth	24
#define dWHeigh	24
#define dRoundR	7

void TDevProperty::DrawFixTextDisplayPad()
{
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "显示匹配方式");
		TextRender_string24(Lv.Grid.Left[2] +42, Lv.Grid.Top[2] + 38, clNearWhite, ItemColor, "分区");
		TextRender_string24(Lv.Grid.Left[2] +140, Lv.Grid.Top[2] + 38, clNearWhite, ItemColor, "二次码");
		//TRoundRect::sDrawBySize(Lv.Grid.Left[2] +226, Lv.Grid.Top[2] + 36, 54, 30, 7, clNearWhite, "读取", 4, clSilver);
	
		TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "显示范围");
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +226, Lv.Grid.Top[3] + 4, 54, 30, 7, clNearWhite, "保存", 4, clNearBlack);

		TextRender_string24(Lv.Grid.Left[4] +10, Lv.Grid.Top[4] + 6, clNearWhite, ItemColor, "操作");
		TRoundRect::sDrawBySize(Lv.Grid.Left[4] +80, Lv.Grid.Top[4] + 40, 60, 30, 7, clNearWhite, "消音", 4, clNearBlack);
		//TRoundRect::sDrawBySize(Lv.Grid.Left[4] +160, Lv.Grid.Top[4] + 40, 104, 30, 7, clNearWhite, "下载注释", 4, clNearBlack);
	}else{
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 6, clNearWhite, ItemColor, "MATCH METHOD");
		TextRender_string24(Lv.Grid.Left[2] +42, Lv.Grid.Top[2] + 38, clNearWhite, ItemColor, "Zone");
		TextRender_string24(Lv.Grid.Left[2] +140, Lv.Grid.Top[2] + 38, clNearWhite, ItemColor, "AuxID");
		//TRoundRect::sDrawBySize(Lv.Grid.Left[2] +226, Lv.Grid.Top[2] + 36, 54, 30, 7, clNearWhite, "读取", 4, clSilver);
	
		TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "DP-RANGE");
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +226, Lv.Grid.Top[3] + 4, 54, 30, 7, clNearWhite, "Save", 4, clNearBlack);

		TextRender_string24(Lv.Grid.Left[4] +10, Lv.Grid.Top[4] + 6, clNearWhite, ItemColor, "OPER");
		TRoundRect::sDrawBySize(Lv.Grid.Left[4] +80, Lv.Grid.Top[4] + 40, 60, 30, 7, clNearWhite, "Mute", 4, clNearBlack);
		//TRoundRect::sDrawBySize(Lv.Grid.Left[4] +160, Lv.Grid.Top[4] + 40, 104, 30, 7, clNearWhite, "LOWNNOTE", 4, clNearBlack);
	}
}

void TDevProperty::FullRedrawhtDisplayPad(int Prm)
{
	if(Prm == 0){
		for(int i=2; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
		ReDrawCommonInf();
		DrawFixTextDisplayPad();
		IList->Edit[0].Show();
		RedrawDisplayPadMatchMode();
		DrawDisplayPadReadWriteStates();
		DisplayPadShowDownloadDescpSta();
		RedrawPanelData();
		Redraw4DisplayPadSmallPanelData();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedHtDisplayPad();
		}
	}else{
		for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		ReDrawCommonInf();
		DrawFixTextDisplayPad();
		IList->Edit[0].Show();
		RedrawDisplayPadMatchMode();
		DrawDisplayPadReadWriteStates();
		DisplayPadShowDownloadDescpSta();
		RedrawPanelData();
		Redraw4DisplayPadSmallPanelData();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedHtDisplayPad();
		}
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

void TDevProperty::DrawDisplayPadReadWriteStates()
{
	char *tText;
	if(IsHotKeyCheckingPermission)return;
	if(VaReadWriteSta ==0 ){
		tText = "        ";
		//TextRender_string24(Lv.Grid.Left[3] + 110, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "        ");
	}else
	if(VaReadWriteSta == 1){
		if(LanguageEnCn==0)tText ="读取成功"; else tText="Read OK ";
		//TextRender_string24(Lv.Grid.Left[3] + 110, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "读取成功");
	}else 
	if(VaReadWriteSta == 2){
		if(LanguageEnCn==0)tText ="读取失败"; else tText="Read Err";
		//TextRender_string24(Lv.Grid.Left[3] + 110, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "读取失败");
	}else
	if(VaReadWriteSta == 3){
		if(LanguageEnCn==0)tText ="保存成功"; else tText="Save OK ";
		//TextRender_string24(Lv.Grid.Left[3] + 110, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "保存成功");
	}else
	if(VaReadWriteSta == 4){
		if(LanguageEnCn==0)tText ="保存失败"; else tText="Save Err";
		//TextRender_string24(Lv.Grid.Left[3] + 110, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "保存失败");
	}else
	if(VaReadWriteSta == 5){
		if(LanguageEnCn==0)tText ="获取中  "; else tText="Reading ";
		//TextRender_string24(Lv.Grid.Left[3] + 110, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "获取中  ");
	}else
	if(VaReadWriteSta == 6){
		if(LanguageEnCn==0)tText ="写入中  "; else tText="Writing ";
		//TextRender_string24(Lv.Grid.Left[3] + 110,  Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "写入中  ");
	}
	TextRender_string24(Lv.Grid.Left[3] + 190, Lv.Grid.Top[2] + 6, clNearWhite, 	ItemColor, 	tText);
}

void TDevProperty::DrawDisplayPadReadWriteStates(unsigned char aNewState)
{
	VaReadWriteSta = aNewState;
	DrawDisplayPadReadWriteStates();
}

void TDevProperty::DisplayPadShowDownloadDescpSta()
{
	char *tText;
	if(DisplayPadDownloadDescpSta == 0){
		tText= "        ";
	}else
	if(DisplayPadDownloadDescpSta == 1){
		if(LanguageEnCn==0)tText ="下载成功"; else tText="Down OK ";
	}else
	if(DisplayPadDownloadDescpSta == 2){
		if(LanguageEnCn==0)tText ="下载失败"; else tText="Down Err";
	}else
	if(DisplayPadDownloadDescpSta == 3){
		if(LanguageEnCn==0)tText ="正在下载"; else tText="OnGoing ";
	}
	TextRender_string24(Lv.Grid.Left[4] + 190, Lv.Grid.Top[4] + 6, clNearWhite, ItemColor, tText);
}

void TDevProperty::DisplayPadShowDownloadDescpSta(unsigned char aSta)
{
	DisplayPadDownloadDescpSta = aSta;
	DisplayPadShowDownloadDescpSta();
}

void TDevProperty::InitHtDisplayPad()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<5; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	
	DrawFixTextDisplayPad();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	
	if( (Path0) && (Path1) && (Path0 <= dPORT_MAX_COUNT) ){
		unsigned char aP0 = Path0 -1;
		for(int i=0; i<dDISPLAYPAD_MAX_COUNT; i++){
			if(Port[aP0].DisplayPadSet[i].Addr == Path1){
				Data.DisplayPadMatchMode = 		Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadByAreaModeBit;
				Data.DisplayPadAreaUsing[0] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingAreaEx0;
				Data.DisplayPadAreaUsing[1] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingAreaEx1;
				Data.DisplayPadAreaUsing[2] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingAreaEx2;
				Data.DisplayPadUserCodeUsing[0] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingUcEx0;
				Data.DisplayPadUserCodeUsing[1] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingUcEx1;
				
				Data.DisplayPadArea0 = Port[aP0].DisplayPadSet[i].AreaEx[0];
				Data.DisplayPadArea1 = Port[aP0].DisplayPadSet[i].AreaEx[1];
				Data.DisplayPadArea2 = Port[aP0].DisplayPadSet[i].AreaEx[2];
				
				Data.DisplayUserCode0 = Port[aP0].DisplayPadSet[i].UcList[0].Full;
				Data.DisplayUserCode1 = Port[aP0].DisplayPadSet[i].UcList[1].Full;
			}
		}
	}
	
	RedrawDisplayPadMatchMode();
	RedrawDisplayPadMatchData();
}

void TDevProperty::EditDescpReturnHtDisplayPad()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<4; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	
	DrawFixTextDisplayPad();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	
	RedrawDisplayPadMatchMode();
	RedrawDisplayPadMatchData();
	
	ReDrawPanel();
}

void TDevProperty::Redraw4DisplayPadNewLoad()
{
	int i;
	unsigned char aP0, aP1;
	Data.DisplayPadMatchMode =0;
	Data.DisplayPadAreaUsing[0] =0;
	Data.DisplayPadAreaUsing[1] =0;
	Data.DisplayPadAreaUsing[2] =0;
	Data.DisplayPadUserCodeUsing[0] =0;
	Data.DisplayPadUserCodeUsing[1] =0;
	Data.DisplayPadArea0 = 0;
	Data.DisplayPadArea1 = 0;
	Data.DisplayPadArea2 = 0;
	Data.DisplayUserCode0 =0;
	Data.DisplayUserCode1 =0;
	
	if( (Path0) && (Path1) && (Path0 <= dPORT_MAX_COUNT) ){
		aP0 = Path0 -1;
		for(i=0; i<dDISPLAYPAD_MAX_COUNT; i++){
			if(Port[aP0].DisplayPadSet[i].Addr == Path1){
				Data.DisplayPadMatchMode = 		Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadByAreaModeBit;
				Data.DisplayPadAreaUsing[0] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingAreaEx0;
				Data.DisplayPadAreaUsing[1] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingAreaEx1;
				Data.DisplayPadAreaUsing[2] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingAreaEx2;
				Data.DisplayPadUserCodeUsing[0] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingUcEx0;
				Data.DisplayPadUserCodeUsing[1] = 	Port[aP0].DisplayPadSet[i].CfgBits & TPort::DisplayPadUsingUcEx1;
				
				Data.DisplayPadArea0 = Port[aP0].DisplayPadSet[i].AreaEx[0];
				Data.DisplayPadArea1 = Port[aP0].DisplayPadSet[i].AreaEx[1];
				Data.DisplayPadArea2 = Port[aP0].DisplayPadSet[i].AreaEx[2];
				
				Data.DisplayUserCode0 = Port[aP0].DisplayPadSet[i].UcList[0].Full;
				Data.DisplayUserCode1 = Port[aP0].DisplayPadSet[i].UcList[1].Full;
			}
		}
	}
	RedrawDisplayPadMatchMode();
	RedrawDisplayPadMatchData();
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
}

void TDevProperty::Redraw4DisplayPadSmallPanelData()
{
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);

	TMyString::sClear(TextDraw);
	TMyString::sFrom2Dg(RuntimeData.voltage % 100, TextDraw);
	TMyString::sAddOnChar('.', TextDraw);
	TMyString::sAddOn1Dg(0, TextDraw);
	TMyString::sAddOnChar('V', TextDraw);
	TextRender_string24(Lv.PanelSmall.Left + 32, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	
	if(LanguageEnCn==0){
		TMyString::sClear(TextDraw);
		TMyString::sAddOnStr("报警", TextDraw);
		TMyString::sAddOn3Dg(RuntimeData.DisplayPadAlramCount % 1000, TextDraw);
		TMyString::sAddOnStr("条", TextDraw);
		TextRender_string24(Lv.PanelSmall.Left + 160, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
		
		TMyString::sClear(TextDraw);
		TMyString::sAddOnStr("报警", TextDraw);
		TMyString::sAddOn3Dg(RuntimeData.DisplayPadAlramCount % 1000, TextDraw);
		TMyString::sAddOnStr("条", TextDraw);
		TextRender_string24(Lv.PanelSmall.Left + 320, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	}else{
		TMyString::sClear(TextDraw);
		TMyString::sAddOnStr("Fire", TextDraw);
		TMyString::sAddOn3Dg(RuntimeData.DisplayPadAlramCount % 1000, TextDraw);
		//TMyString::sAddOnStr("条", TextDraw);
		TextRender_string24(Lv.PanelSmall.Left + 160, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
		
		TMyString::sClear(TextDraw);
		TMyString::sAddOnStr("Fire", TextDraw);
		TMyString::sAddOn3Dg(RuntimeData.DisplayPadAlramCount % 1000, TextDraw);
		//TMyString::sAddOnStr("条", TextDraw);
		TextRender_string24(Lv.PanelSmall.Left + 320, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);		
	}
	
	DrawMac();
}

void TDevProperty::ClearSelectedHtDisplayPad()
{
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 0;
			IList->EditPortNum.Show();
			break;
		case 2:
			IList->EditAddrNum.Selected = 0;
			IList->EditAddrNum.Show();
			break;
		case 3:
			IList->EditDescpShow.Selected = 0;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 0;
			IList->EditUserCode.Show();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 0;
			IList->EditAreaAssign.Show();
			break;
		case 6:
			TRoundSquare::sSelected(Lv.Grid.Left[2] +12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 7:
			TRoundSquare::sSelected(Lv.Grid.Left[2] +110, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 8:
			if(LanguageEnCn==0)tText="读取"; else tText="Read";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +226, Lv.Grid.Top[2] + 36, 54, 30, 7, clNearWhite, tText, 4, clNearBlack);
			break;
		case 9:
			if(LanguageEnCn==0)tText="保存"; else tText="Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +226, Lv.Grid.Top[3] + 4, 54, 30, 7, clNearWhite, tText, 4, clNearBlack);
			break;
	}
	if(Data.DisplayPadMatchMode == 0){
		switch(Tag.Inx){
			case 10:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, ItemColor);
				break;
			case 11:
				IList->Edit[0].Selected = 0;
				IList->Edit[0].Show();
			case 12:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, ItemColor);
				break;
			case 13:
				IList->Edit[1].Selected = 0;
				IList->Edit[1].Show();
				break;
			
			
			case 14:
				if(LanguageEnCn==0)tText="消音"; else tText="Mute";
				TRoundRect::sDrawBySize(Lv.Grid.Left[4] +80, Lv.Grid.Top[4] + 40, 60, 30, 7, clNearWhite, tText, 4, clNearBlack);
				break;
			case 15:
				//TRoundRect::sDrawBySize(Lv.Grid.Left[4] +160, Lv.Grid.Top[4] + 40, 104, 30, 7, clNearWhite, "下载注释", 4, clNearBlack);
				break;
		}
	}else{
		switch(Tag.Inx){
			case 10:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, ItemColor);
				break;
			case 11:
				IList->Edit[0].Selected = 0;
				IList->Edit[0].Show();
			case 12:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, ItemColor);
				break;
			case 13:
				IList->Edit[1].Selected = 0;
				IList->Edit[1].Show();
				break;
			case 14:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, ItemColor);
				break;
			case 15:
				IList->Edit[2].Selected = 0;
				IList->Edit[2].Show();
				break;
			
			
			case 16:
				if(LanguageEnCn==0)tText="消音"; else tText="Mute";
				TRoundRect::sDrawBySize(Lv.Grid.Left[4] +80, Lv.Grid.Top[4] + 40, 60, 30, 7, clNearWhite, tText, 4, clNearBlack);
				break;
			case 17:
				//TRoundRect::sDrawBySize(Lv.Grid.Left[4] +160, Lv.Grid.Top[4] + 40, 104, 30, 7, clNearWhite, "下载注释", 4, clNearBlack);
				break;
		}
	}
}
void TDevProperty::Check4SelectedHtDisplayPad()
{
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 1;
			IList->EditPortNum.SetPstTail();
			IList->EditPortNum.Show();
			IList->EditPortNum.ShowCursor();
			break;
		case 2:
			IList->EditAddrNum.Selected = 1;
			IList->EditAddrNum.SetPstTail();
			IList->EditAddrNum.Show();
			IList->EditAddrNum.ShowCursor();
			break;
		case 3:
			IList->EditDescpShow.Selected = 1;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 1;
			IList->EditUserCode.SetPstTail();
			IList->EditUserCode.Show();
			IList->EditUserCode.ShowCursor();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 1;
			IList->EditAreaAssign.SetPstTail();
			IList->EditAreaAssign.Show();
			IList->EditAreaAssign.ShowCursor();
			break;
		case 6:
			TRoundSquare::sSelected(Lv.Grid.Left[2] +12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 7:
			TRoundSquare::sSelected(Lv.Grid.Left[2] +110, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 8:
			if(LanguageEnCn==0)tText="读取"; else tText="Read";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +226, Lv.Grid.Top[2] + 36, 54, 30, 7, clDeepBlue, tText, 4, clNearWhite);
			break;
		case 9:
			if(LanguageEnCn==0)tText="保存"; else tText="Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +226, Lv.Grid.Top[3] + 4, 54, 30, 7, clDeepBlue, tText, 4, clNearWhite);
			break;
	}
	if(Data.DisplayPadMatchMode == 0){
		switch(Tag.Inx){
			case 10:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, clNearWhite);
				break;
			case 11:
				IList->Edit[0].Selected = 1;
				IList->Edit[0].Show();
				break;
			case 12:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, clNearWhite);
				break;
			case 13:
				IList->Edit[1].Selected = 1;
				IList->Edit[1].Show();
				break;
			
			case 14:
				if(LanguageEnCn==0)tText="消音"; else tText="Mute";
				TRoundRect::sDrawBySize(Lv.Grid.Left[4] +80, Lv.Grid.Top[4] + 40, 60, 30, 7, clDeepBlue, tText, 4, clNearWhite);
				break;
			case 15:
				//TRoundRect::sDrawBySize(Lv.Grid.Left[4] +160, Lv.Grid.Top[4] + 40, 104, 30, 7, clDeepBlue, "下载注释", 4, clNearWhite);
				break;
		}
	}else{
		switch(Tag.Inx){
			case 10:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, clNearWhite);
				break;
			case 11:
				IList->Edit[0].Selected = 1;
				IList->Edit[0].Show();
				break;
			case 12:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, clNearWhite);
				break;
			case 13:
				IList->Edit[1].Selected = 1;
				IList->Edit[1].Show();
				break;
			case 14:
				TRoundSquare::sSelected(Lv.Grid.Left[3] +200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, 4, clNearWhite);
				break;
			case 15:
				IList->Edit[2].Selected = 1;
				IList->Edit[2].Show();
				break;
			case 16:
				if(LanguageEnCn==0)tText="消音"; else tText="Mute";
				TRoundRect::sDrawBySize(Lv.Grid.Left[4] +80, Lv.Grid.Top[4] + 40, 60, 30, 7, clDeepBlue, tText, 4, clNearWhite);
				break;
			case 17:
				//TRoundRect::sDrawBySize(Lv.Grid.Left[4] +160, Lv.Grid.Top[4] + 40, 104, 30, 7, clDeepBlue, "下载注释", 4, clNearWhite);
				break;
		}
	}		
}

void TDevProperty::RedrawDisplayPadMatchMode()
{
	if(Data.DisplayPadMatchMode){
		//1 By Area Num
		TRoundSquare::sDrawBySize(Lv.Grid.Left[2] + 12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[2] + 110, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}else{
		//0 By User Code
		TRoundSquare::sDrawBySize(Lv.Grid.Left[2] + 12, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(Lv.Grid.Left[2] + 110, Lv.Grid.Top[2] + 38, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
	}
}

void TDevProperty::RedrawDisplayPadMatchData()
{
	for(int i=3; i<4; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "显示范围");
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +226, Lv.Grid.Top[3] + 4, 54, 30, 7, clNearWhite, "保存", 4, clNearBlack);
	}else{
		TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 6, clNearWhite, ItemColor, "DP-RANGE");
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +226, Lv.Grid.Top[3] + 4, 54, 30, 7, clNearWhite, "Save", 4, clNearBlack);
	}
	if(Data.DisplayPadMatchMode){
		//1 By Area Num
		if(Data.DisplayPadAreaUsing[0])
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		else
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);			
		if(Data.DisplayPadAreaUsing[1])
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		else
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		if(Data.DisplayPadAreaUsing[2])
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		else
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		IList->Edit[0].Init(Lv.Grid.Left[3] + 34, Lv.Grid.Top[3] + 38, 60, 32, 0,0,1,ItemColor);
		IList->Edit[1].Init(Lv.Grid.Left[3] + 132, Lv.Grid.Top[3] + 38, 60, 32, 0,0,1,ItemColor);
		IList->Edit[2].Init(Lv.Grid.Left[3] + 228, Lv.Grid.Top[3] + 38, 60, 32, 0,0,1,ItemColor);
		IList->Edit[0].Str.Clear();
		IList->Edit[1].Str.Clear();
		IList->Edit[2].Str.Clear();
		IList->Edit[0].SetMaxLen(4);
		IList->Edit[1].SetMaxLen(4);
		IList->Edit[2].SetMaxLen(4);
		
		IList->Edit[0].Str.FromUInt4Dg(Data.DisplayPadArea0);
		IList->Edit[1].Str.FromUInt4Dg(Data.DisplayPadArea1);
		IList->Edit[2].Str.FromUInt4Dg(Data.DisplayPadArea2);
		
		IList->Edit[0].Show();
		IList->Edit[1].Show();
		IList->Edit[2].Show();
	}else{
		//0 By User Code
		if(Data.DisplayPadUserCodeUsing[0])
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		else
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		if(Data.DisplayPadUserCodeUsing[1])
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		else
			TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		IList->Edit[0].Init(Lv.Grid.Left[3] + 42, Lv.Grid.Top[3] + 38, 104, 32, 0,0,1,ItemColor);
		IList->Edit[1].Init(Lv.Grid.Left[3] + 184, Lv.Grid.Top[3] + 38, 104, 32, 0,0,1,ItemColor);
		
		IList->Edit[0].Str.Clear();
		IList->Edit[1].Str.Clear();
		IList->Edit[0].SetMaxLen(8);
		IList->Edit[1].SetMaxLen(8);
		
		LoadUcBcdText(Data.DisplayUserCode0, IList->Edit[0].Str.Text);
		LoadUcBcdText(Data.DisplayUserCode1, IList->Edit[1].Str.Text);
		
		IList->Edit[0].Show();
		IList->Edit[1].Show();
	}
}

void TDevProperty::PushDisplayPadCanData(unsigned char aCmd, unsigned char *pData)
{
	int i;
	if(aCmd == cmSetDisplayPadPositionInf){
		for(i=0; i<8; i++)RecData[i] = pData[i];
		if(   (1 == RecData[0]) &&
			(MainCtl.fData.Split.MyNum == RecData[1]) &&
			(Path0 == RecData[2]) &&
			(Path1 == RecData[3]) ) {
				DisplayPadRt.RecRdy =1;
				DisplayPadRt.RecCmd =aCmd;
		}
	}
}

TGuiMsgReturn TDevProperty::KeyInHtDisplayPad(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	int HasPrc = 0;
	switch(aKey){
		case VK_0:
		case VK_1:
		case VK_2:
		case VK_3:
		case VK_4:
		case VK_5:
		case VK_6:
		case VK_7:
		case VK_8:
		case VK_9:
		case VK_DELETE:
		case VK_LEFT:
		case VK_RIGHT:
		case dfKEY_ASTERISK:
			if(Tag.Inx < 6){
				KeyInCommonEdit(aKey);
			}else{
				if(Tag.Inx == 6){
					if(aKey == VK_RIGHT){
						ClearSelectedHtDisplayPad();
						Tag.Inx = 7;
						Check4SelectedHtDisplayPad();
					}
				}else
				if(Tag.Inx == 7){
					if(aKey == VK_RIGHT){
						ClearSelectedHtDisplayPad();
						Tag.Inx = 9;
						Check4SelectedHtDisplayPad();
					}else
					if(aKey == VK_LEFT){
						ClearSelectedHtDisplayPad();
						Tag.Inx = 6;
						Check4SelectedHtDisplayPad();
					}
				}else
				if(Tag.Inx == 8){
					
				}else
				if(Tag.Inx == 9){

				}else{
					if(Data.DisplayPadMatchMode){
						if(Tag.Inx == 10){
							if(aKey == VK_RIGHT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 11;
								Check4SelectedHtDisplayPad();
							}
						}else
						if(Tag.Inx == 11){
							if(aKey == VK_LEFT){
								if(IList->Edit[0].Pst < 0){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 10;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}else
							if(aKey == VK_LEFT){
								if(IList->Edit[0].Pst >= IList->Edit[0].Str.GetLength()){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 12;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}
							if( (HasPrc == 0) && (aKey != dfKEY_ASTERISK) ){
								IList->Edit[0].KeyIn(aKey);
								IList->Edit[0].Show();
								IList->Edit[0].ShowCursor();
							}
						}else
						if(Tag.Inx == 12){
							if(aKey == VK_RIGHT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 13;
								Check4SelectedHtDisplayPad();
							}else
							if(aKey == VK_LEFT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 11;
								Check4SelectedHtDisplayPad();
							}
						}else
						if(Tag.Inx == 13){
							if(aKey == VK_LEFT){
								if(IList->Edit[1].Pst < 0){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 12;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}else
							if(aKey == VK_LEFT){
								if(IList->Edit[1].Pst >= IList->Edit[1].Str.GetLength()){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 14;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}
							if( (HasPrc == 0) && (aKey != dfKEY_ASTERISK) ){
								IList->Edit[1].KeyIn(aKey);
								IList->Edit[1].Show();
								IList->Edit[1].ShowCursor();
							}
						}else
						if(Tag.Inx == 14){
							if(aKey == VK_LEFT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 13;
								Check4SelectedHtDisplayPad();
							}
						}else
						if(Tag.Inx == 15){
							if(aKey == VK_LEFT){
								if(IList->Edit[2].Pst < 0){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 14;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}
							if( (HasPrc == 0) && (aKey != dfKEY_ASTERISK) ){
								IList->Edit[2].KeyIn(aKey);
								IList->Edit[2].Show();
								IList->Edit[2].ShowCursor();
							}
						}else
						if(Tag.Inx == 16){
							//Mute
							//if(aKey == VK_RIGHT){
							//	ClearSelectedHtDisplayPad();
							//	Tag.Inx = 17;
							//	Check4SelectedHtDisplayPad();
							//}
						}else
						if(Tag.Inx == 17){
							//DownLoad Descp
							if(aKey == VK_LEFT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 16;
								Check4SelectedHtDisplayPad();
							}
						}
					}else{
						if(Tag.Inx == 10){
							if(aKey == VK_RIGHT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 11;
								Check4SelectedHtDisplayPad();
							}
						}
						if(Tag.Inx == 11){
							if(aKey == VK_LEFT){
								if(IList->Edit[0].Pst < 0){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 10;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}else
							if(aKey == VK_RIGHT){
								if(IList->Edit[0].Pst >= IList->Edit[0].Str.GetLength()){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 12;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}
							if( (HasPrc == 0) ){
								IList->Edit[0].KeyIn(aKey);
								IList->Edit[0].Show();
								IList->Edit[0].ShowCursor();
							}
						}else
						if(Tag.Inx == 12){
							if(aKey == VK_LEFT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 11;
								Check4SelectedHtDisplayPad();
							}else
							if(aKey == VK_RIGHT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 13;
								Check4SelectedHtDisplayPad();
							}
						}else
						if(Tag.Inx == 13){
							if(aKey == VK_LEFT){
								if(IList->Edit[1].Pst < 0){
									ClearSelectedHtDisplayPad();
									Tag.Inx = 12;
									Check4SelectedHtDisplayPad();
									HasPrc = 1;
								}
							}
							if( (HasPrc == 0) ){
								IList->Edit[1].KeyIn(aKey);
								IList->Edit[1].Show();
								IList->Edit[1].ShowCursor();
							}
						}else
						if(Tag.Inx == 14){
							//Mute
							//if(aKey == VK_RIGHT){
							//	ClearSelectedHtDisplayPad();
							//	Tag.Inx = 15;
							//	Check4SelectedHtDisplayPad();
							//}
						}else
						if(Tag.Inx == 15){
							//DownLoad Descp
							if(aKey == VK_LEFT){
								ClearSelectedHtDisplayPad();
								Tag.Inx = 14;
								Check4SelectedHtDisplayPad();
							}
						}
					}
				}
			}
			break;
		case VK_UP:
			if(PortNumValid && AddrNumValid){
				ClearSelectedHtDisplayPad();
				if(Data.DisplayPadMatchMode){
					Tag.Inx > Tag.InxMin ? Tag.Inx-- : Tag.Inx = 17;
					if(Tag.Inx == 8)Tag.Inx =7;
				}else{
					Tag.Inx > Tag.InxMin ? Tag.Inx-- : Tag.Inx = 15;
					if(Tag.Inx == 8)Tag.Inx =7;
				}
				Check4SelectedHtDisplayPad();
			}
			break;
		case VK_DOWN:
			if(PortNumValid && AddrNumValid){
				ClearSelectedHtDisplayPad();
				if(Data.DisplayPadMatchMode){
					Tag.Inx < 16 ? Tag.Inx++ : Tag.Inx = Tag.InxMin;
					if(Tag.Inx == 8)Tag.Inx =9;
				}else{
					Tag.Inx < 14 ? Tag.Inx++ : Tag.Inx = Tag.InxMin;
					if(Tag.Inx == 8)Tag.Inx =9;
				}
				Check4SelectedHtDisplayPad();
			}
			break;
		case VK_TAB:
			//PanelIsUsingText = PanelIsUsingText ? 0 : 1;
			break;
		case dfKEY_SETUP:
			if(Tag.Inx == 6){
				Data.DisplayPadMatchMode = Data.DisplayPadMatchMode ? 0 : 1;
				RedrawDisplayPadMatchMode();
				RedrawDisplayPadMatchData();
			}else
			if(Tag.Inx == 7){
				Data.DisplayPadMatchMode = Data.DisplayPadMatchMode ? 0 : 1;
				RedrawDisplayPadMatchMode();
				RedrawDisplayPadMatchData();
			}else
			if(Data.DisplayPadMatchMode){
				if(Tag.Inx == 10){
					Data.DisplayPadAreaUsing[0] = Data.DisplayPadAreaUsing[0] ? 0 : 1;
					if(Data.DisplayPadAreaUsing[0])
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
					else
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
				}else
				if(Tag.Inx == 12){
					Data.DisplayPadAreaUsing[1] = Data.DisplayPadAreaUsing[1] ? 0 : 1;								
					if(Data.DisplayPadAreaUsing[1])
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
					else
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
					
				}else
				if(Tag.Inx == 14){
					Data.DisplayPadAreaUsing[2] = Data.DisplayPadAreaUsing[2] ? 0 : 1;								
					if(Data.DisplayPadAreaUsing[2])
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
					else
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
					
				}
			}else{
				if(Tag.Inx == 10){
					Data.DisplayPadUserCodeUsing[0] = Data.DisplayPadUserCodeUsing[0] ? 0 : 1;
					if(Data.DisplayPadUserCodeUsing[0])
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
					else
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);

				}else
				if(Tag.Inx == 12){
					Data.DisplayPadUserCodeUsing[1] = Data.DisplayPadUserCodeUsing[1] ? 0 : 1;
					if(Data.DisplayPadUserCodeUsing[1])
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
					else
						TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
				}
			}			
			break;
		case dfKEY_QUERY:
			PanelDrawData.DesertTextHex = PanelDrawData.DesertTextHex ? 0: 1;
			break;
		case dfKEY_ENCN:
			SendReqMac();
			break;
		case VK_EXECUTE:
			if(PortNumValid && AddrNumValid){
				if(Tag.Inx <6){
					KeyInCommonEnter(aKey);
				}else{
					if(Tag.Inx == 6){
						Data.DisplayPadMatchMode = Data.DisplayPadMatchMode ? 0 : 1;
						RedrawDisplayPadMatchMode();
						RedrawDisplayPadMatchData();
					}else
					if(Tag.Inx == 7){
						Data.DisplayPadMatchMode = Data.DisplayPadMatchMode ? 0 : 1;
						RedrawDisplayPadMatchMode();
						RedrawDisplayPadMatchData();
					}else
					if(Tag.Inx == 8){
						//Read Data
						
					}else
					if(Tag.Inx == 9){
						//Save Data
						if( (Path0) && (Path1) && (Path0 <= dPORT_MAX_COUNT) ){
							PermissionCmd = pcWriteDisplayPadMatchData;
							if(SystemPermission >2){
								PermissionCmdGO();
							}else{
								IsPermission = 1;
								PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
							}
						}
					}else{
						if(Data.DisplayPadMatchMode){
							if(Tag.Inx == 10){
								Data.DisplayPadAreaUsing[0] = Data.DisplayPadAreaUsing[0] ? 0 : 1;
								if(Data.DisplayPadAreaUsing[0])
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
								else
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 6, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
							}else
							if(Tag.Inx == 11){
								//is Editor, Do nothing
							}else
							if(Tag.Inx == 12){
								Data.DisplayPadAreaUsing[1] = Data.DisplayPadAreaUsing[1] ? 0 : 1;								
								if(Data.DisplayPadAreaUsing[1])
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
								else
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 104, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
								
							}else
							if(Tag.Inx == 13){
								//is Editor, Do nothing
							}else
							if(Tag.Inx == 14){
								Data.DisplayPadAreaUsing[2] = Data.DisplayPadAreaUsing[2] ? 0 : 1;								
								if(Data.DisplayPadAreaUsing[2])
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
								else
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 200, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
								
							}else
							if(Tag.Inx == 15){
								//is Editor, Do nothing
							}else
							if(Tag.Inx == 16){
								//Mute
								if(SystemPermission >1){
									SendDisplayPadMute();
								}else{
									IsPermission = 1;
									PermissionCmd = pcDisplayPadMute;
									PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 2);
								}
							}else
							if(Tag.Inx == 17){
								//DownLoad Descp
								//PermissionCmd = pcDownLoadDescp;
								//PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 2);
							}
						}else{
							if(Tag.Inx == 10){
								Data.DisplayPadUserCodeUsing[0] = Data.DisplayPadUserCodeUsing[0] ? 0 : 1;
								if(Data.DisplayPadUserCodeUsing[0])
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
								else
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 12, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		
							}else
							if(Tag.Inx == 11){
								//is Editor, Do nothing
							}else
							if(Tag.Inx == 12){
								Data.DisplayPadUserCodeUsing[1] = Data.DisplayPadUserCodeUsing[1] ? 0 : 1;
								if(Data.DisplayPadUserCodeUsing[1])
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
								else
									TRoundSquare::sDrawBySize(Lv.Grid.Left[3] + 154, Lv.Grid.Top[3] + 42, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
							}else
							if(Tag.Inx == 13){
								//is Editor, Do nothing
							}else
							if(Tag.Inx == 14){
								//Mute
								SendDisplayPadMute();
							}else
							if(Tag.Inx == 15){
								//DownLoad Descp
								PermissionCmd = pcDownLoadDescp;
								if(SystemPermission >2){
									PermissionCmdGO();
								}else{
									IsPermission = 1;
									PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
								}
							}
						}
					}
				}
			}
			break;
		case VK_RETURN:
			IsShow = 0;
			RealTimeSendCmdAbort();
			aMsg = guiMsgReturn;
			break;
	}
	
	return aMsg;
	
}

void TDevProperty::SendDisplayPadMute()
{
	SendCmdMuteBroadcast();
	SendCmdMute();
}	

void TDevProperty::SendDisplayPadDescpDownload()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	volatile unsigned int tAddr;
	int iVal;
	unsigned char aPx;
	
	Len =4;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	CommData[0] = 0;
	CommData[1] = Path0;
	CommData[2] = Path1;
	CommData[3] = 0;
	
	aIde.BitF.Cmd = cmSetDisplayPadPositionInf;
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	DisplayPadRt.IsDownloadDescp =1;
	DisplayPadRt.RecRdy = 0;
	DisplayPadRt.WaitTick =0;
	DisplayPadShowDownloadDescpSta(3);	//"正在下载");

	Len = 8;
	for(i=0; i<32; i++){
		DisplayPadRt.DescpText[i] = '\0';
	}
	if((Path0)&&(Path1)){
		if((Path0<=dPORT_MAX_COUNT) && (Path1<=dEP_MAX_COUNT_PER_PORT)){
			tAddr = dAddrSdRam_Descp + ((Path0-1) * 256 * 32) + ((Path1-1) * 32);
			for(i=0; i<32; i++)DisplayPadRt.DescpText[i] = *(volatile unsigned char *)(tAddr +i);
		}
	}
	for(int Inx=0; Inx<8; Inx++){
		CommData[3] = Inx +1;
		CommData[4] = DisplayPadRt.DescpText[Inx *4 +0];
		CommData[5] = DisplayPadRt.DescpText[Inx *4 +1];
		CommData[6] = DisplayPadRt.DescpText[Inx *4 +2];
		CommData[7] = DisplayPadRt.DescpText[Inx *4 +3];
		InnerCan.Buf4GuiSend.Insert(aIde, CommData, Len);
	}
}

void TDevProperty::WriteDisplayPadMatchData()
{
	int i;
	unsigned char aP0;
	
	DrawDisplayPadReadWriteStates(0);
	
	for(i=0; i<16; i++)DpSetting.MemBytes[i] =0;
	
	if(Path0 == 0)return;
	if(Path0 > dPORT_MAX_COUNT)return;
	aP0 = Path0-1;
	DpSetting.Addr = Path1;
	
	if(Data.DisplayPadMatchMode)		DpSetting.CfgBits |= TPort::DisplayPadByAreaModeBit;
	if(Data.DisplayPadAreaUsing[0])	DpSetting.CfgBits |= TPort::DisplayPadUsingAreaEx0;
	if(Data.DisplayPadAreaUsing[1])	DpSetting.CfgBits |= TPort::DisplayPadUsingAreaEx1;
	if(Data.DisplayPadAreaUsing[2])	DpSetting.CfgBits |= TPort::DisplayPadUsingAreaEx2;
	if(Data.DisplayPadUserCodeUsing[0])	DpSetting.CfgBits |= TPort::DisplayPadUsingUcEx0;
	if(Data.DisplayPadUserCodeUsing[1])	DpSetting.CfgBits |= TPort::DisplayPadUsingUcEx1;
	
	if(Data.DisplayPadMatchMode){
		DpSetting.AreaEx[0] = IList->Edit[0].Str.ToInteger();
		DpSetting.AreaEx[1] = IList->Edit[1].Str.ToInteger();
		DpSetting.AreaEx[2] = IList->Edit[2].Str.ToInteger();
		if(DpSetting.AreaEx[0] > dAreaCountMax)DpSetting.AreaEx[0] =0;
		if(DpSetting.AreaEx[1] > dAreaCountMax)DpSetting.AreaEx[1] =0;
		if(DpSetting.AreaEx[2] > dAreaCountMax)DpSetting.AreaEx[2] =0;
		
		for(i=0; i<dDISPLAYPAD_MAX_COUNT; i++){
			if(Port[aP0].DisplayPadSet[i].Addr == Path1){
				DpSetting.UcList[0].Full = Port[aP0].DisplayPadSet[i].UcList[0].Full;
				DpSetting.UcList[1].Full = Port[aP0].DisplayPadSet[i].UcList[1].Full;
			}
		}
	}else{
		DpSetting.UcList[0].Full = RestoreUcBcdText(IList->Edit[0].Str.Text);
		DpSetting.UcList[1].Full = RestoreUcBcdText(IList->Edit[1].Str.Text);
		
		for(i=0; i<dDISPLAYPAD_MAX_COUNT; i++){
			if(Port[aP0].DisplayPadSet[i].Addr == Path1){
				DpSetting.AreaEx[0] = Port[aP0].DisplayPadSet[i].AreaEx[0];
				DpSetting.AreaEx[1] = Port[aP0].DisplayPadSet[i].AreaEx[1];
				DpSetting.AreaEx[2] = Port[aP0].DisplayPadSet[i].AreaEx[2];
			}
		}
	}
	Port[aP0].SortDisplayPad();
	Port[aP0].SetOneDisplayPadSetting(DpSetting.MemBytes);
	Port[aP0].SortDisplayPad();
	
	//write 2 Flash
	unsigned int aAddr;
	volatile unsigned int aWait;
	volatile unsigned int aFlashState;
	do{
		sDelayMs(2);
		aFlashState = nor_get_busy_state(0);
	}while(aFlashState);
	
	//Erase 
	aAddr = dFlashRegisterDataAddr + (dFlashRegisterPortDataLen * aP0) + (256 * 0);
	nor_erase_sector_4k(dFlashRegisterDataChip,aAddr);
	do{
		sDelayMs(2);
		aFlashState = nor_get_busy_state(0);
	}while(aFlashState);
	
	//Write
	TRegister::sIList = IList;
	TRegister::sWriteOnePort(aP0+1);
	
	//Read Back
	Record.ReadRegisterDataOnePort(i+1);
	Record.ReadPortDisplayPadSet(i+1);

	//Reload
	Redraw4DisplayPadNewLoad();
	Check4SelectedHtDisplayPad();
	DrawDisplayPadReadWriteStates(3);
}

void TDevProperty::Task1000MsDisplayPad()
{
	if(DisplayPadRt.IsDownloadDescp){
		if(DisplayPadRt.RecRdy){
			if(DisplayPadRt.RecCmd == cmSetDisplayPadPositionInf){
				DisplayPadRt.RecRdy = 0;
				DisplayPadRt.IsDownloadDescp = 0;
				//Add Record Here
				
				if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
					DisplayPadShowDownloadDescpSta(1);	//"下载成功"); 
				}else{
					DisplayPadDownloadDescpSta = 1;
				}
			}
			DisplayPadRt.RecRdy = 0;
		}
		DisplayPadRt.WaitTick ++;
		if(DisplayPadRt.WaitTick > 10){
			DisplayPadRt.IsDownloadDescp = 0;
			if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
				DisplayPadShowDownloadDescpSta(2);// "下载失败");
			}else{
				DisplayPadDownloadDescpSta = 2;
			}
		}
	}
	Redraw4DisplayPadSmallPanelData();
}








