#pragma once

// MultiEditListCtrl.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMultiEdit window

class CMultiEditListCtrl;

class CMultiEdit : public CEdit
{
		CMultiEditListCtrl *m_pListCtrl;
		int                 m_nItem;
		int                 m_nSubItem;

		void                SetItem();

// Construction
	public:
		CMultiEdit();

// Attributes
	public:

// Operations
	public:
		void                Attach(CMultiEditListCtrl *pListCtrl, int nItem, int nSubItem);

// Implementation
	public:
		virtual ~CMultiEdit();

		// Generated message map functions
	protected:
		afx_msg void OnKillFocus(CWnd *pNewWnd);
		afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
		afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
		DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
// CMultiEditListCtrl window

class CMultiEditListCtrl : public CListCtrl
{
		CMultiEdit         *m_pEdit;
		CFont               m_font;
		bool                m_bDigits;  //флаг, что можно принимать только цифры
	protected:
		struct ITEM_INFO
		{
			bool            bEditable;
			bool            bModified;
			bool            bEdited;
			DWORD           nValue;
			COLORREF        clrText;
			COLORREF        clrTextBk;
			ITEM_INFO(): bEditable(true), bModified(false), bEdited(false), nValue(0xffffffff) {};
		};
		CArray <ITEM_INFO *, ITEM_INFO *> m_colorTable;

		COLORREF            m_StdColor;
		COLORREF            m_StdBgColor;

		enum                {MODIFIED_COLOR = RGB(255, 0, 0)};

		void                InitColorTable();
		void                ClearColorTable();
		int                 GetColumnNumber();

	public:
		CMultiEditListCtrl();
		virtual ~CMultiEditListCtrl();
		void                AcceptDigits(bool bDigits)
		{
			m_bDigits = bDigits;
		}
		bool                IsDigitsOnly()
		{
			return m_bDigits;
		}
		void                EnableEdit(bool bEnable, int nItem, int nColumn);
		void                EnableRowEdit(bool bEnable, int nRow);
		void                EnableColumnEdit(bool bEnable, int nColumn);
		void                SetItemColor(COLORREF col, int nItem, int nColumn);
		void                SetRowColor(COLORREF col, int nRow);
		void                SetColumnColor(COLORREF col, int nColumn);
		void                SetItemBkColor(COLORREF col, int nItem, int nColumn);
		void                SetRowBkColor(COLORREF col, int nRow);
		void                SetColumnBkColor(COLORREF col, int nColumn);
		void                SetItemWithModified(register WORD word, register int nItem, register int nSubitem, bool bColored = true);
		void                SetItemWithModifiedASCII(CString &str, register int nItem, register int nSubitem);
		void                SetEndEdit(int nItem, int nSubitem);
// Overrides
	protected:
		virtual void        PreSubclassWindow() override;

// Generated message map functions
	protected:
		afx_msg BOOL OnDblclk(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg void OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg BOOL OnInsertitem(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg BOOL OnDeleteitem(NMHDR *pNMHDR, LRESULT *pResult);
		afx_msg BOOL OnDeleteallitems(NMHDR *pNMHDR, LRESULT *pResult);
		DECLARE_MESSAGE_MAP()
};


