/* OCaml-Win32
 * win32_progressbar.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: Progress Bar Controls */

/* Styles */

static DWORD progressbar_style_options[] = {
    PBS_SMOOTH,
    PBS_VERTICAL
};
Define_static_constants(progressbar_style_options);

CAMLprim value progressbar_style_of_option(value option)
{
    return copy_int64((int64)Constant_val(option, progressbar_style_options));
}

/* Messages */

CAMLprim value pack_pbm_deltapos(value delta)
{
    return pack_message(PBM_DELTAPOS, Int_val(delta), 0);
}

CAMLprim value unpack_pbm_deltapos(value result)
{
    return Val_int(Int32_val(result));
}

CAMLprim value unpack_pbm_getpos(value result)
{
    return Val_int(Int32_val(result));
}

CAMLprim value issue_pbm_getrange(value sender)
{
    CAMLparam1(sender);
    PBRANGE pbr;
    CAMLlocal2(contents, val);

    contents = pack_message(PBM_GETRANGE, FALSE, (LPARAM)&pbr);
    callback(sender, contents);
    val = alloc_tuple(2);
    Store_field(val, 0, Val_int(pbr.iLow));
    Store_field(val, 1, Val_int(pbr.iHigh));
    CAMLreturn(val);
}

CAMLprim value pack_pbm_setbarcolor(value color)
{
    return pack_message(PBM_SETBARCOLOR, 0, (LPARAM)color_val(color));
}

CAMLprim value unpack_pbm_setbarcolor(value result)
{
    return alloc_color((COLORREF)Int32_val(result));
}

CAMLprim value pack_pbm_setbkcolor(value color)
{
    return pack_message(PBM_SETBKCOLOR, 0, (LPARAM)color_val(color));
}

CAMLprim value unpack_pbm_setbkcolor(value result)
{
    return alloc_color((COLORREF)Int32_val(result));
}

CAMLprim value pack_pbm_setpos(value pos)
{
    return pack_message(PBM_SETPOS, Int_val(pos), 0);
}

CAMLprim value unpack_pbm_setpos(value result)
{
    return Val_int(Int32_val(result));
}

CAMLprim value pack_pbm_setrange(value min, value max)
{
    return pack_message(PBM_SETRANGE, 0, MAKELPARAM(Int_val(min), Int_val(max)));
}

CAMLprim value unpack_pbm_setrange(value result)
{
    CAMLparam1(result);
    CAMLlocal1(val);

    val = alloc_tuple(2);
    Store_field(val, 0, Val_int(LOWORD(Int32_val(result))));
    Store_field(val, 1, Val_int(HIWORD(Int32_val(result))));
    CAMLreturn(val);
}

CAMLprim value pack_pbm_setrange32(value min, value max)
{
    return pack_message(PBM_SETRANGE32, Int_val(min), Int_val(max));
}

CAMLprim value unpack_pbm_setrange32(value result)
{
    CAMLparam1(result);
    CAMLlocal1(val);

    val = alloc_tuple(2);
    Store_field(val, 0, Val_int(LOWORD(Int32_val(result))));
    Store_field(val, 1, Val_int(HIWORD(Int32_val(result))));
    CAMLreturn(val);
}

CAMLprim value pack_pbm_setstep(value step)
{
    return pack_message(PBM_SETSTEP, Int_val(step), 0);
}

CAMLprim value unpack_pbm_setstep(value result)
{
    return Val_int(Int32_val(result));
}

CAMLprim value unpack_pbm_stepit(value result)
{
    return Val_int(Int32_val(result));
}
