#pragma once

// DisasmCtrl.h : header file
//
#include "DebuggerItemParam.h"
#include "MultiEditListCtrl.h"
#include <mutex>

// массив номеров колонок списка
enum DISASM_LIST : int
{
	COL_MARK = 0,
	COL_ADDR,
	COL_INSTR,
	COL_COMMENT,
};


class CDebugger;

/////////////////////////////////////////////////////////////////////////////
// CDisasmCtrl window

class CDisasmCtrl : public CMultiEditListCtrl
{
		DECLARE_DYNAMIC(CDisasmCtrl)

		CDebugger          *m_pDebugger{ nullptr };
		int                 m_nSelection{ -1 };
		std::mutex          m_lock;

		HICON               m_hBPIcon{nullptr}, m_hCurrIcon{ nullptr };
		HICON               m_hBPIconOff{ nullptr }, m_hBPIconMem{ nullptr }, m_hBPIconMemOff{ nullptr };

		std::vector<CDbgItemParam> m_vItemsParam;

// Construction
	public:
		CDisasmCtrl();
		virtual ~CDisasmCtrl() override;

// Operations
	public:
		void                OutContent();
		void                Init();
		uint16_t            GetCursorAddr() const;
		uint16_t            GetBottomAddr() const;
		int                 GetLinesCount() const;
		int                 GetLineFromAddr(uint16_t addr);
		void                DisasmStepDn(const int nCount = 1) const;

	protected:
		void                EditAsmInstr(const int nRow, const int nCol);
		void                DisasmStepUp(const int nCount = 1) const;
		void                DrawColoredText(CDC *pDC, CRect &rect, CString &str);
		void                SetSelected(int nIdx);
		uint16_t            GetLineAddress(int nRow) const;
		uint16_t            StepBackward(const int nSteps = 1) const;
		uint16_t            StepForward(const int nSteps = 1) const;
		CString             GetDisasmParTxt(CDbgItemParam &p);
		CString             GetArgText(const CDbgItemParam &p, const ARGTYPE::ARGTYPE t);
		CString             GetAddrText(const CDbgItemParam &p, const ARGTYPE::ARGTYPE t);
		CString             GetFPUArgText(const CDbgItemParam &p, const ARGTYPE::ARGTYPE t);
		CString             GetFloatNum(const CDbgItemParam::argParam &ap, int size);

		virtual BOOL        PreTranslateMessage(MSG *pMsg) override;
		// Generated message map functions
	protected:
		afx_msg void OnSize(UINT nType, int cx, int cy);
		afx_msg void OnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnLVNKeyDown(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnSetFocus(CWnd *pOldWnd);
		afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
		DECLARE_MESSAGE_MAP()
};

