/* OCaml-Win32
 * win32_hotkey.c
 * Copyright (c) 2002-2004 by Harry Chomsky
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "win32.h"

/********************************************************************/
/* User Interface: Windows User Experience: Windows Shell: SDK: Windows Controls: Individual Control Information: Hot Key Controls */

static DWORD hotkey_modifiers[] = {
    HOTKEYF_ALT,
    HOTKEYF_CONTROL,
    HOTKEYF_EXT,
    HOTKEYF_SHIFT
};
Define_static_constants(hotkey_modifiers);

/* Messages */

CAMLprim value unpack_hkm_gethotkey(value result)
{
    CAMLparam1(result);
    WORD res;
    CAMLlocal2(val, v);

    res = LOWORD(Int32_val(result));
    val = alloc_tuple(2);
    v = alloc_virtualkeycode(LOBYTE(res));
    Store_field(val, 0, v);
    v = Alloc_flags(HIBYTE(res), hotkey_modifiers);
    Store_field(val, 1, v);
    CAMLreturn(val);
}

CAMLprim value pack_hkm_sethotkey(value hotkey)
{
    BYTE vk;
    BYTE mod;

    vk = virtualkeycode_val(Field(hotkey, 0));
    mod = (BYTE)flags_val(Field(hotkey, 1), hot_key_modifiers);
    return pack_message(HKM_SETHOTKEY, MAKEWORD(vk, mod), 0);
}

static DWORD hotkey_combinations[] = {
    HKCOMB_A,
    HKCOMB_C,
    HKCOMB_CA,
    HKCOMB_NONE,
    HKCOMB_S,
    HKCOMB_SA,
    HKCOMB_SC,
    HKCOMB_SCA
};
Define_static_constants(hotkey_combinations);

CAMLprim value pack_hkm_setrules(value invalid, value modifiers)
{
    return pack_message(HKM_SETRULES, flags_val(invalid, hotkey_combinations), flags_val(modifiers, hotkey_modifiers));
}
