/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef GAMOS_KEYCODES_H
#define GAMOS_KEYCODES_H

#include "common/keyboard.h"

namespace Gamos {

class KeyCodes {

public:
	enum {
		WIN_INVALID = 0,

		WIN_LBUTTON = 0x01,
		WIN_RBUTTON = 0x02,
		WIN_CANCEL = 0x03,
		WIN_MBUTTON = 0x04,
		WIN_XBUTTON1 = 0x05,
		WIN_XBUTTON2 = 0x06,
		WIN_BACK = 0x08,
		WIN_TAB = 0x09,
		WIN_CLEAR = 0x0C,
		WIN_RETURN = 0x0D,
		WIN_SHIFT = 0x10,
		WIN_CONTROL = 0x11,
		WIN_MENU = 0x12,
		WIN_PAUSE = 0x13,
		WIN_CAPITAL = 0x14,
		WIN_KANA = 0x15,
		WIN_JUNJA = 0x17,
		WIN_FINAL = 0x18,
		WIN_KANJI = 0x19,
		WIN_ESCAPE = 0x1B,
		WIN_CONVERT = 0x1C,
		WIN_NONCONVERT = 0x1D,
		WIN_ACCEPT = 0x1E,
		WIN_MODECHANGE = 0x1F,
		WIN_SPACE = 0x20,
		WIN_PRIOR = 0x21,
		WIN_NEXT = 0x22,
		WIN_END = 0x23,
		WIN_HOME = 0x24,
		WIN_LEFT = 0x25,
		WIN_UP = 0x26,
		WIN_RIGHT = 0x27,
		WIN_DOWN = 0x28,
		WIN_SELECT = 0x29,
		WIN_PRINT = 0x2A,
		WIN_EXECUTE = 0x2B,
		WIN_SNAPSHOT = 0x2C,
		WIN_INSERT = 0x2D,
		WIN_DELETE = 0x2E,
		WIN_HELP = 0x2F,
		WIN_0 = 0x30,
		WIN_1 = 0x31,
		WIN_2 = 0x32,
		WIN_3 = 0x33,
		WIN_4 = 0x34,
		WIN_5 = 0x35,
		WIN_6 = 0x36,
		WIN_7 = 0x37,
		WIN_8 = 0x38,
		WIN_9 = 0x39,
		WIN_A = 0x41,
		WIN_B = 0x42,
		WIN_C = 0x43,
		WIN_D = 0x44,
		WIN_E = 0x45,
		WIN_F = 0x46,
		WIN_G = 0x47,
		WIN_H = 0x48,
		WIN_I = 0x49,
		WIN_J = 0x4A,
		WIN_K = 0x4B,
		WIN_L = 0x4C,
		WIN_M = 0x4D,
		WIN_N = 0x4E,
		WIN_O = 0x4F,
		WIN_P = 0x50,
		WIN_Q = 0x51,
		WIN_R = 0x52,
		WIN_S = 0x53,
		WIN_T = 0x54,
		WIN_U = 0x55,
		WIN_V = 0x56,
		WIN_W = 0x57,
		WIN_X = 0x58,
		WIN_Y = 0x59,
		WIN_Z = 0x5A,
		WIN_LWIN = 0x5B,
		WIN_RWIN = 0x5C,
		WIN_APPS = 0x5D,
		WIN_SLEEP = 0x5F,
		WIN_NUMPAD0 = 0x60,
		WIN_NUMPAD1 = 0x61,
		WIN_NUMPAD2 = 0x62,
		WIN_NUMPAD3 = 0x63,
		WIN_NUMPAD4 = 0x64,
		WIN_NUMPAD5 = 0x65,
		WIN_NUMPAD6 = 0x66,
		WIN_NUMPAD7 = 0x67,
		WIN_NUMPAD8 = 0x68,
		WIN_NUMPAD9 = 0x69,
		WIN_MULTIPLY = 0x6A,
		WIN_ADD = 0x6B,
		WIN_SEPARATOR = 0x6C,
		WIN_SUBTRACT = 0x6D,
		WIN_DECIMAL = 0x6E,
		WIN_DIVIDE = 0x6F,
		WIN_F1 = 0x70,
		WIN_F2 = 0x71,
		WIN_F3 = 0x72,
		WIN_F4 = 0x73,
		WIN_F5 = 0x74,
		WIN_F6 = 0x75,
		WIN_F7 = 0x76,
		WIN_F8 = 0x77,
		WIN_F9 = 0x78,
		WIN_F10 = 0x79,
		WIN_F11 = 0x7A,
		WIN_F12 = 0x7B,
		WIN_F13 = 0x7C,
		WIN_F14 = 0x7D,
		WIN_F15 = 0x7E,
		WIN_F16 = 0x7F,
		WIN_F17 = 0x80,
		WIN_F18 = 0x81,
		WIN_F19 = 0x82,
		WIN_F20 = 0x83,
		WIN_F21 = 0x84,
		WIN_F22 = 0x85,
		WIN_F23 = 0x86,
		WIN_F24 = 0x87,
		WIN_NAVIGATION_VIEW = 0x88,
		WIN_NAVIGATION_MENU = 0x89,
		WIN_NAVIGATION_UP = 0x8A,
		WIN_NAVIGATION_DOWN = 0x8B,
		WIN_NAVIGATION_LEFT = 0x8C,
		WIN_NAVIGATION_RIGHT = 0x8D,
		WIN_NAVIGATION_ACCEPT = 0x8E,
		WIN_NAVIGATION_CANCEL = 0x8F,
		WIN_NUMLOCK = 0x90,
		WIN_SCROLL = 0x91,
		WIN_OEM_NEC_EQUAL = 0x92,
		WIN_OEM_FJ_JISHO = 0x92,
		WIN_OEM_FJ_MASSHOU = 0x93,
		WIN_OEM_FJ_TOUROKU = 0x94,
		WIN_OEM_FJ_LOYA = 0x95,
		WIN_OEM_FJ_ROYA = 0x96,
		WIN_LSHIFT = 0xA0,
		WIN_RSHIFT = 0xA1,
		WIN_LCONTROL = 0xA2,
		WIN_RCONTROL = 0xA3,
		WIN_LMENU = 0xA4,
		WIN_RMENU = 0xA5,
		WIN_BROWSER_BACK = 0xA6,
		WIN_BROWSER_FORWARD = 0xA7,
		WIN_BROWSER_REFRESH = 0xA8,
		WIN_BROWSER_STOP = 0xA9,
		WIN_BROWSER_SEARCH = 0xAA,
		WIN_BROWSER_FAVORITES = 0xAB,
		WIN_BROWSER_HOME = 0xAC,
		WIN_VOLUME_MUTE = 0xAD,
		WIN_VOLUME_DOWN = 0xAE,
		WIN_VOLUME_UP = 0xAF,
		WIN_MEDIA_N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ICK_DOWN = 0xD8,
		WIN_GAMEPAD_RIGHT_THUMBSTICK_RIGHT = 0xD9,
		WIN_GAMEPAD_RIGHT_THUMBSTICK_LEFT = 0xDA,
		WIN_OEM_4 = 0xDB,
		WIN_OEM_5 = 0xDC,
		WIN_OEM_6 = 0xDD,
		WIN_OEM_7 = 0xDE,
		WIN_OEM_8 = 0xDF,
		WIN_OEM_AX = 0xE1,
		WIN_OEM_102 = 0xE2,
		WIN_ICO_HELP = 0xE3,
		WIN_ICO_00 = 0xE4,
		WIN_PROCESSKEY = 0xE5,
		WIN_ICO_CLEAR = 0xE6,
		WIN_PACKET = 0xE7,
		WIN_OEM_RESET = 0xE9,
		WIN_OEM_JUMP = 0xEA,
		WIN_OEM_PA1 = 0xEB,
		WIN_OEM_PA2 = 0xEC,
		WIN_OEM_PA3 = 0xED,
		WIN_OEM_WSCTRL = 0xEE,
		WIN_OEM_CUSEL = 0xEF,
		WIN_OEM_ATTN = 0xF0,
		WIN_OEM_FINISH = 0xF1,
		WIN_OEM_COPY = 0xF2,
		WIN_OEM_AUTO = 0xF3,
		WIN_OEM_ENLW = 0xF4,
		WIN_OEM_BACKTAB = 0xF5,
		WIN_ATTN = 0xF6,
		WIN_CRSEL = 0xF7,
		WIN_EXSEL = 0xF8,
		WIN_EREOF = 0xF9,
		WIN_PLAY = 0xFA,
		WIN_ZOOM = 0xFB,
		WIN_NONAME = 0xFC,
		WIN_PA1 = 0xFD,
		WIN_OEM_CLEAR = 0xFE
	};

private:
	uint8 _winCodes[Common::KEYCODE_LAST];
	uint16 _scummCodes[256];

	Common::Array<uint8> _cpTable;

protected:
	KeyCodes();

	void setCPTable(const uint16 *table, uint16 size, uint16 offset = 0x80);

public:
	uint8 getWinCode(uint16 code) const {
		return _winCodes[code];
	};
	uint16 getScummCode(uint8 code) const {
		return _scummCodes[code];
	};

	void setCP1251();
	void setCP1252();

	uint16 getCPCode(uint16 code) const {
		if (code >= _cpTable.size())
			return 0;
		return _cpTable[code];
	}
};


}


#endif
