#ifndef _COMMON_KEYDATA_HPP_
#define _COMMON_KEYDATA_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif

class KeyData
{
public:
  KeyData(void);
	KeyData(WPARAM virtualKey,LPARAM keyData);
	KeyData(const KeyData &someKeyData);
	KeyData(const CallbackData &someCallbackData);
	virtual ~KeyData();
	KeyData &operator=(const KeyData &someKeyData);
	BOOL operator==(const KeyData &someKeyData)const;
	int virtualKey(void)const;
	int repeatCount(void)const;
	int scanCode(void)const;
	BOOL isExtendedKey(void)const;
	BOOL isEnterKey(void)const;
	BOOL isEscapeKey(void)const;
	BOOL contextCode(void)const;
	BOOL prevKeyUp(void)const;
	BOOL transitionState(void)const;
  static bool shiftKeyPressed(void);
	static bool controlKeyPressed(void);
private:
  enum {EnterKey=0x0D,EscapeKey=0x1B};
  WPARAM mVirtualKey;
	LPARAM mKeyData;
};

inline
KeyData::KeyData(void)
: mVirtualKey(0), mKeyData(0)
{
}

inline
KeyData::KeyData(const KeyData &someKeyData)
{
  *this=someKeyData;
}

inline
KeyData::KeyData(WPARAM virtualKey,LPARAM keyData)
: mVirtualKey(virtualKey), mKeyData(keyData)
{
}

inline
KeyData::KeyData(const CallbackData &someCallbackData)
: mVirtualKey(someCallbackData.wParam()), mKeyData(someCallbackData.lParam())
{
}

inline
KeyData::~KeyData()
{
}

inline
KeyData &KeyData::operator=(const KeyData &someKeyData)
{
  mVirtualKey=someKeyData.mVirtualKey;
	mKeyData=someKeyData.mKeyData;
	return *this;
}

inline
BOOL KeyData::operator==(const KeyData &someKeyData)const
{
  return mVirtualKey==someKeyData.mVirtualKey&&
	       mKeyData==someKeyData.mKeyData;
}

inline
int KeyData::virtualKey(void)const
{
  return mVirtualKey;
}

inline
int KeyData::repeatCount(void)const
{
  return mKeyData&0xFFFF;
}

inline
int KeyData::scanCode(void)const
{
  return (mKeyData&0xFF00)>>16;
}

inline
BOOL KeyData::isExtendedKey(void)const
{
  return mKeyData&0x100000;
}

inline
BOOL KeyData::isEnterKey(void)const
{
  return virtualKey()==EnterKey;
}

inline
BOOL KeyData::isEscapeKey(void)const
{
  return virtualKey()==EscapeKey;
}

inline
BOOL KeyData::contextCode(void)const
{
  return mKeyData&0x20000000;
}

inline
BOOL KeyData::prevKeyUp(void)const
{
  return mKeyData&0x40000000;
}

inline
BOOL KeyData::transitionState(void)const
{
  return mKeyData&0x80000000;
}

inline
bool KeyData::shiftKeyPressed(void)
{
  return ::GetKeyState(VK_SHIFT)&0x8000;
}

inline
bool KeyData::controlKeyPressed(void)
{
  return ::GetKeyState(VK_CONTROL)&0x8000;
}
#endif