#ifndef LISTVIEWDEVICE_H_
#define LISTVIEWDEVICE_H_

#include "gType.h" 
#include "GraphBase.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "my_string.h"
#include "Device.h"
#include "EpDevice.h"
#include "DevProperty.h"
#include "Icon.h"

#define dLISTVIEW_TYPE_DUMP		0
#define dLISTVIEW_TYPE_SYS		1
#define dLISTVIEW_TYPE_EP		2
#define dLISTVIEW_TYPE_PORT		3
#define dLISTVIEW_TYPE_HANDCTL	4
#define dLISTVIEW_TYPE_DIRECTCTL	5

#define dLISTVIEW_STYLE_LIST		0
#define dLISTVIEW_STYLE_ICON		1
#define dLISTVIEW_VSCOLLBAR_WIDTH	20

//For Device View or Edit
class TListViewDevice{
	public:
		static constexpr unsigned short hList[12] = {34,34,34,34,	34,34,34,34,	34,34,34,34};
		static constexpr unsigned short wList[12] = {800,800,800,800,	800,800,800,800,	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]) +4,
			.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.Top[8] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]),
			.Grid.Top[9] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]),
			.Grid.Top[10] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]),
			.Grid.Top[11] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + (2 + hList[10]),
				
			.Grid.Bottom[0] = (36 + 32 +2) + hList[0],
			.Grid.Bottom[1] = (36 + 32 +2) + (2 + hList[0]) + hList[1] +4,
			.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.Bottom[8] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + hList[8],
			.Grid.Bottom[9] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + hList[9],
			.Grid.Bottom[10] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + hList[10],
			.Grid.Bottom[11] = (36 + 32 +2) + (2 + hList[0]) + (6 + hList[1]) + (2 + hList[2]) + (2 + hList[3]) + (2 + hList[4]) + (2 + hList[5]) + (2 + hList[6]) + (2 + hList[7]) + (2 + hList[8]) + (2 + hList[9]) + (2 + hList[10]) + hList[11],
			
			.Grid.UsingCount = 10,
			
			.Panel.Active = 0,
			.Panel.ItemType = piMemo,
			.PanelSmall.Active = 0,
		};
	public:
		class TCtlPanel1	*aPanel;
		class TItemList	*IList;
		int FontSize;
		int FontHeight;
		int EditMode;
		int Editing;
		int Quering;
		class TEdit	Edit;
		struct{
			int TopIndex;
			unsigned short RowCount;
			unsigned short ColTop[12];
			unsigned short ColBottom[12];
			unsigned short ColHeight;
			unsigned short ColWidth[12];
			unsigned short ColLeft[12];
			unsigned short ColRight[12];
			unsigned short FixColTop;
			unsigned short FixColBottom;
			unsigned int  TransparrentColor;
			int SelectedCol;
		}ListView;
		struct{
			struct{
				int SelectedIndex;
				int ListTopIndex;
				int IconLeftTopIndex;
			}Path0;
			struct{
				int SelectedIndex;
				int ListTopIndex;
				int IconLeftTopIndex;
			}Path1;
		}Bk;
		struct{
			int Count;
			int Inx;
			int TopInx;
			int Path;
			unsigned char Item[256];
			void Reset(){
				Inx = 0;
				TopInx = 0;
				Path = 0;
			}
		}Items[3];
		unsigned char SelectedType;
		struct{
			unsigned short Path0;
			unsigned short Path1;
			TRootDevice *RootDev;
			TEpDevice *EpDev;
		}ItemEnter;
		unsigned char TypeAndCount[256];
		unsigned char TypeCount;
		unsigned char TypeCountIndex;
		unsigned char TypeCountPageIndex;
		unsigned char TypeCountPageCount;
		unsigned char TypeCharHasShow;
		
		char Text[80];
		unsigned char TextInputIndex;
		
		int DrawX,DrawY;
		int LastDrawX,LastDrawY;
		
		int CircuitShowFig;
		struct{
			unsigned int Smoke;
			unsigned int Tempe;
			unsigned int HandReport;
			unsigned int HydKp;
			unsigned int ModuleInput;
			unsigned int ModuleInOut;
			unsigned int ModuleOutput;
			unsigned int Va;
			unsigned int FDisplay;
			unsigned int SmokeTempe;
			unsigned int cOther;
			
			unsigned int Tt;
		}Count;
		int IsPath0Found;
		unsigned char Path0;
		struct{
			int ViewingLevel;
			struct{
				int Inx;
			}Level[3];
			void Reset(){
				ViewingLevel =0;
				Level[0].Inx = 0;
				Level[1].Inx = 0;
				Level[2].Inx = 0;
			}
		}Tag;
	public:
		TIcon Icon;
		TStaticText Caption;
		TStaticText SText;
		unsigned int ViewPath;
		unsigned int ViewStyle;
		int ActiveLineNum;
		int LineCount;
		int LineHeight;
		float ScrollVertical;
	
		u32 FixColColor;
		u32 FixColTextColor;
		u32 Color;
		u32 TextColor;
		u32 SelectedColor;
		u32 SelectedTextColor;
	
		int TabOrder;
	
		TPoint OwnerLeftTop; //ParrentLeftTop;
		TRect Bound;	
		TRect VScrollBarBox;
		TRect Content;
		
		int IsShow;
		
		TDevProperty *DevProperty;
	private:
		void CalcIconDrawPrm(void);
		void SetListColWidth(int w0, int w1, int w2, int w3, int w4,int w5,int w6, int w7, int w8);
		void LoadPath1Item(TEpDevice *pItem);
	
		void DrawVScrollBar_ListView(void);
		void DrawVScrollBar_IconView(void);
		TGuiMsgReturn QueryKeyIn(unsigned char aKey);
		TGuiMsgReturn EditKeyIn(unsigned char aKey);
		
	public:
		TListViewDevice(){};
		void Init();
		void LoadPath0Item();
		void SetFontSize(int size);		
		unsigned int ItemGetIcon(unsigned int aIndex);
		
		void RenderBackGround(void);
		void RenderBackGround(unsigned int aClr);
		void DrawSelfLevel0(void);
		void DrawSelfLevel1(void);
		void DrawSelfLevel2(void);
		void DrawLevel1Detail(void);
		void DrawVertScrollBar(void);
		void DrawShortList(void);
		void DrawList(void);
		void Show(void);
		void ReDraw(void);
		void DrawCaption(void);
		void DrawCaption2(void);
		void RenderContent(void);
		void ClearSpliteCount();
		void GetSpliteCount(unsigned char aP0);
		void ShowFig(unsigned char aP0);
		void ShowCount();
		void ShowCircuitDet();
		void FullRedraw(int Prm);
		
		TGuiMsgReturn KeyIn(unsigned char aKey);
		
		void ClearPath(void);
		void ClearPath1(void);
		void LoadPath0(void);
		void LoadPath1(unsigned char aP0);
		void GetTypeAndCount();
		int  FindStartPoint();
		void SetEditMode(unsigned int aMode);
		
		void CheckNewLine(int aLen);
		void ShowTypeList(unsigned char aP0, unsigned char Type1, unsigned char Type2, int Is2Type, char *p, int tLen);
		void ShowCount(unsigned char aP0);
		
		void FullRePaint(void);
		void RePaint(void);
		
		void DevPropertyInit(void);
		
		void ClearSelectedLv0(void);
		void Check4SelectedLv0(void);
		void ClearSelectedLv1(void);
		void Check4SelectedLv1(void);
		
		int ExtRequst(unsigned char Prm){
			if(this->DevProperty != nullptr)
				this->DevProperty->ExtRequst(Prm);
			IsShow = 0;
			return 0;
		}
};











#endif


