#pragma once
#include "MultiEditListCtrl.h"
#include "LockVarType.h"

enum DUMP_DISPLAY_MODE
{
	DD_WORD_VIEW = 0,
	DD_BYTE_VIEW
};

#define MAX_DUMP_COLS_WORD  4
#define MAX_DUMP_COLS_BYTE  8
#define COLUMN_WIDTH_ADDR   60
#define COLUMN_WIDTH_WORD   68
#define COLUMN_WIDTH_BYTE   34
#define COLUMN_WIDTH_TXT    70


class CDumpListCtrl :
	public CMultiEditListCtrl
{
		DUMP_DISPLAY_MODE m_DisplayMode;

		WORD            m_nTopAddr; //адрес верхнего итема списка
		WORD            m_nBottomAddr; //адрес нижнего итема списка

		LockVarType     m_lockDraw;
		LockVarType     m_lockChangeMode;

	public:
		CDumpListCtrl(void);
		virtual ~CDumpListCtrl(void);

		enum
		{
			IDS_MEMORY_ADDR_WORD = 0,
			IDS_MEMORY_COLUMN1_WORD,
			IDS_MEMORY_COLUMN2_WORD,
			IDS_MEMORY_COLUMN3_WORD,
			IDS_MEMORY_COLUMN4_WORD,
			IDS_MEMORY_ASCII_WORD
		};
		enum
		{
			IDS_MEMORY_ADDR_BYTE = 0,
			IDS_MEMORY_COLUMN1_BYTE,
			IDS_MEMORY_COLUMN2_BYTE,
			IDS_MEMORY_COLUMN3_BYTE,
			IDS_MEMORY_COLUMN4_BYTE,
			IDS_MEMORY_COLUMN5_BYTE,
			IDS_MEMORY_COLUMN6_BYTE,
			IDS_MEMORY_COLUMN7_BYTE,
			IDS_MEMORY_COLUMN8_BYTE,
			IDS_MEMORY_ASCII_BYTE
		};

		TCHAR GetMemDumpByteAsANSI(BYTE byte);
		void Init(DUMP_DISPLAY_MODE mode);
		void RefreshItems(WORD nNewAddr = 0, BOOL bNewAddrIsValid = FALSE);
		inline const DUMP_DISPLAY_MODE GetDisplayMode()
		{
			return m_DisplayMode;
		}
		inline const WORD GetDumpAddress()
		{
			return m_nTopAddr;
		}
		void SetDisplayMode(DUMP_DISPLAY_MODE mode);
		void SetItemWithModifiedByte(BYTE byte, int nItem, int nSubitem, BOOL bColored = TRUE);

	protected:
		void SetHeader();
		void AdjustRows();
		void AdjustScroll();
		void SetEditAddress();
		void ChangeAddr();
		void InsertNewLine(int nNum);

	protected:
		virtual BOOL PreCreateWindow(CREATESTRUCT &cs);
		afx_msg void OnSize(UINT nType, int cx, int cy);
		afx_msg void OnLvnKeydown(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar);
		afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
		DECLARE_MESSAGE_MAP()
};

