#ifndef USERCODESET_H_
#define USERCODESET_H_

#include "gType.h" 
#include "GraphBase.h"
#include "string.h"
#include "my_string.h"
#include "Device.h"
#include "EpDevice.h"
#include "StaticText.h"
#include "CtlPanel1.h"
#include "EditML.h"

//#pragma pack(push, 1)

class TUserCodeSet{
	public:
		static constexpr unsigned short hList[12] = {78,74,40,40,	40,40,40,32,	32,32,32,32};
		static constexpr unsigned short wList[12] = {800,290,290,290,	290,290,290,290,	800,800,800,800};
		static constexpr TLv Lv = {
			.Caption.Left = 0,
			.Caption.Top = 36,
			.Caption.Width = 800,
			.Caption.Heigh = 32,
			.Caption.Right = 800 -0 -1,
			.Caption.Bottom = 36 + 32,
			
			.Grid.Left = {0,0,0,0,	0,0,0,0,	0,0,0,0},
			.Grid.Right = {wList[0]-1,wList[1]-1,wList[2]-1,wList[3]-1,	wList[4]-1,wList[5]-1,wList[6]-1,wList[7]-1,	wList[8]-1,wList[9]-1,wList[10]-1,wList[11]-1},
			.Grid.Top[0] = (36 + 32 +2),
			.Grid.Top[1] = (36 + 32 +2) + (2 + hList[0]) +2,
			.Grid.Top[2] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]),
			.Grid.Top[3] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]),
			.Grid.Top[4] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]),
			.Grid.Top[5] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]),
			.Grid.Top[6] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]),
			.Grid.Top[7] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]),
				
			.Grid.Bottom[0] = (36 + 32 +2) + hList[0],
			.Grid.Bottom[1] = (36 + 32 +2) + (2 + hList[0]) + hList[1] +2,
			.Grid.Bottom[2] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + hList[2],
			.Grid.Bottom[3] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + hList[3],
			.Grid.Bottom[4] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + hList[4],
			.Grid.Bottom[5] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + hList[5],
			.Grid.Bottom[6] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + hList[6],
			.Grid.Bottom[7] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + hList[7],
			
			.Grid.UsingCount = 7,
				
			.Panel.ItemType = piMemo,
			.Panel.Left = wList[1] + 6,
			.Panel.Top = (36 + 32 +2) + hList[0] +8,
			.Panel.Width = 502,
			.Panel.Heigh = 282,
			.Panel.Right = wList[1] + 6 + 502 -1,
			.Panel.Bottom = (36 + 32 +2) + hList[0] +6 + 282 -1,
			
			.Panel.Active = 1,
			.Panel.ItemType = piMemo,
			.PanelSmall.Active = 0,
		};
		static constexpr TPoint ResultTipPoint = {
			.x = Lv.Grid.Left[6] + 10,
			.y = Lv.Grid.Top[6] + 8,
		};
	public:
		int IsShow;
		class TEditML	mlEdit;
		class TItemList	*IList;
		class TCtlPanel1	*aPanel;
	
		unsigned char PortNum;
		unsigned char AddrStart;
		unsigned char AddrEnd;
		unsigned char dType;
	
		unsigned char PortValid;
		unsigned char AddrStartValid;
		unsigned char AddrEndValid;
		unsigned char dTypeValid;
	
		unsigned int AreaNum;
	
		unsigned char IncDec;
		unsigned char IsList;
		unsigned char IsPermission;
		unsigned char PermissionCmd;
		
		unsigned int CtlIndex;
		
		int Sta;
		
		char RawData[64];
		char UserCodeStr[8];
	
		unsigned char IsEdittingDescp;
		unsigned char IsExtInput;
		unsigned char IsEdittingShortName;
	
		int ItemCount;
		int ListPage;
		char ListText[20];
		
		unsigned char GotAst;
		unsigned int UserCodePrv;
		unsigned int UserCode;
		
		unsigned int UserCodeStart;
		unsigned int UserCodeItv;
	public:
		TUserCodeSet(){};
		void Init();
		static void DelayMs(unsigned int aMs);
		
		void RenderBackGround(void);
		void RenderBackGround(unsigned int aClr);
		void DrawSelf(void);
		void DrawIncDec();
		int DrawDetail();
		
		void Show(void);
		void ReDraw(void);
		void FullRedraw(int Prm);
		void ShowSta();
		void ShowSta(int aSta);
		void DrawCount();
		void DrawList();
		void DrawFixText();
		
		TGuiMsgReturn KeyIn(unsigned char aKey);
		
		void InitPanel();
		void ClearSelected(void);
		void Check4Selected(void);
		
		void CheckCount();
		void LoadAssignType();
		void LoadUcBcdText();
		void LoadShortName();
		void LoadData();
		
		void PermissionCmdGO();
		void PermissionCmdReturnDraw();
			
		void ReadAllFromFlash();
		void ReadEntryViaFlash();
		void Write2Flash();
		
		int ExtRequst(unsigned char Prm){IsShow =0; return 0;}
	
};

























//#pragma pack(pop)



#endif

