#pragma once
#include <atlimage.h>

enum BKKeyType : int
{
	BKKEY_RESERVED,
	BKKEY_REGULAR,
	BKKEY_LSHIFT,
	BKKEY_RSHIFT,
	BKKEY_CTRL,
	BKKEY_ALT,
	BKKEY_ZAGL,
	BKKEY_STR,
	BKKEY_STOP,
	BKKEY_ENDARRAY
};

struct BKKey
{
	BKKeyType nType;
	int x1;
	int y1;
	int x2;
	int y2;
	BYTE nScanCode;
	BYTE nInt;
};


class CBKKbdButn : public CWnd
{
	protected:
		HWND    m_hwndParent; //хэндл родительского окна
		CWnd    *m_cwndParent; //указатель на родительское окно

		CImage m_Img;
		CImage m_Img_p;   // Для битмапа-нажиматора
		CImage m_ImgScr;

		int m_cx;
		int m_cy;
		int m_imgW;
		int m_imgH;
		int m_nIdx;

		int m_nAR2Index;
		int m_nSUIndex;
		int m_nLShiftIndex;
		int m_nRShiftIndex;
		int m_nArraySize;

		bool m_bAR2Pressed;
		bool m_bSUPressed;
		bool m_bLShiftPressed;
		bool m_bRShiftPressed;
		bool m_bIsZag;
		bool m_bControlKeyPressed;
		bool m_bRegularKeyPressed;

		BKKey *m_pBKKeyboardArray;

		static const BKKey m_ButnKbdKeys[];
		static const BKKey m_PlenKbdKeys[];

	public:
		CBKKbdButn(UINT nID = 0);
		virtual ~CBKKbdButn();
		virtual BOOL DestroyWindow() override;
		void AdjustLayout();
		void SetID(UINT nID);
		inline int GetWidth()
		{
			return m_imgW;
		}
		inline int GetHeihgt()
		{
			return m_imgH;
		}
	protected:
		virtual BOOL PreCreateWindow(CREATESTRUCT &cs) override;
		int GetKeyIndex(int x, int y);
		int GetKeyIndexById(BKKeyType nType);
		int GetArraySize();
		void _FocusPressedkey(int nIdx);
		BYTE TranslateScanCode(BYTE nScanCode);
		void ControlKeysUp();
		void ClearObj();

		afx_msg LRESULT OnRealKeyDown(WPARAM wParam, LPARAM lParam);
		afx_msg LRESULT OnRealKeyUp(WPARAM wParam, LPARAM lParam);
		afx_msg void OnPaint();
		afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
		afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
		afx_msg BOOL OnEraseBkgnd(CDC *pDC);
		afx_msg void OnSize(UINT nType, int cx, int cy);
		DECLARE_MESSAGE_MAP()
};

