/*
 * synergy -- mouse and keyboard sharing utility
 * Copyright (C) 2004 Chris Schoeneman
 * Copyright (C) 2006 Knut St. Osmundsen
 *
 * This package is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * found in the file COPYING that should have accompanied this file.
 *
 * This package 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.
 */

#ifndef CPMUTIL_H
#define CPMUTIL_H

#include "CString.h"
#define INCL_BASE
#define INCL_ERRORS
#define INCL_PM
#include <os2.h>

class CPMUtil {
public:
	//! Get message string
	/*!
	Gets a string for \p id from the string table of \p instance.
	*/
	static CString		getString(HMODULE hmod, ULONG id);

	//! Get error string
	/*!
	Gets a system error message for \p error.  If the error cannot be
	found return the string for \p id, replacing ${1} with \p error.
	*/
	static CString		getErrorString(HMODULE hmod, ULONG error, ULONG id);

    static HAB          getHAB(void);
    static HMQ          getHMQ(HAB hab = NULLHANDLE);

};

/** The WinTranlateChar2 operation. */
typedef enum WINTCOP
{
    TC_CHARTOSCANCODE = 0,
    TC_SCANCODETOCHAR,
    TC_VIRTUALKEYTOSCANCODE,
    TC_SCANCODETOVIRTUALKEY,
    TC_SCANTOOEMSCAN,
    TC_OEMSCANTOSCAN,
    TC_SIZE_HACK = 0x7fff
} WINTCOP;

/** @name WinTranslateChar2 shift state.
 * This state goes with scancode input/output.
 * @{ */
#define TCF_LSHIFT          0x1
#define TCF_RSHIFT          0x2
#define TCF_SHIFT           (TCF_LSHIFT | TCF_RSHIFT)
#define TCF_LCONTROL        0x4
#define TCF_RCONTROL        0x8
#define TCF_CONTROL         (TCF_LCONTROL | TCF_RCONTROL)
#define TCF_ALT             0x10
#define TCF_ALTGR           0x20
#define TCF_CAPSLOCK        0x40
#define TCF_NUMLOCK         0x80
#define TCF_MAX_BITS        8       /**< bits 0-7 are real shift states */
#define TCF_OEMSCANCODE     0x100
#define TCF_EXTENDEDKEY     0x200
/** @} */

/**
 * Char to/from keyboard code translator.
 *
 * @returns A combination of some of the KC_* values.
 * @param   usCodePage          The code page. Anything goes, apparently ignored.
 * @param   pusCharInOut        Where to get the char/code to be translated and to
 *                              put the output upon return.
 * @param   pulDeadKeyInfo      Previous, dead key.
 * @param   enmOperation        The kind of translation.
 * @param   pfShiftState        Where to read/store the shift state. Used when
 *                              translating from/to scancodes.
 * @remark  PMWIN.1070
 */
extern "C"
USHORT APIENTRY WinTranslateChar2(USHORT  usCodePage,
                                  PUSHORT pusCharInOut,
                                  PULONG  pulDeadKeyInfo,
                                  WINTCOP enmOperation,
                                  PUSHORT pfShiftState);

#endif

