(* OCaml-Win32
 * win32_pager.ml
 * 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.
 *)

open Win32_core

(********************************************************************)
(* User Interface: Windows User Experience: Windows Shell: SDK: Windows Controls: Individual Control Information: Pager Controls *)

let wc_pagescroller = "SysPager"

(* Styles *)

type pager_style_option =
    PGS_AUTOSCROLL
  | PGS_DRAGNDROP
  | PGS_HORZ

external pager_style_of_option : pager_style_option -> style = "pager_style_of_option"

let pager_style_of_options = special_style_of_options ~special_func:pager_style_of_option

(* Messages *)

let pgm_first = 0x1400

let pgm_forwardmouse = pgm_first + 3
external pack_pgm_forwardmouse : forward:bool -> message_contents = "pack_pgm_forwardmouse"
let unpack_pgm_forwardmouse = ignore
let issue_pgm_forwardmouse ~sender ~forward = unpack_pgm_forwardmouse (sender ~msg:(pack_pgm_forwardmouse ~forward))

let pgm_getbkcolor = pgm_first + 5
let pack_pgm_getbkcolor = pack_simple_message ~id:pgm_getbkcolor
external unpack_pgm_getbkcolor : message_result -> color = "unpack_pgm_getbkcolor"
let issue_pgm_getbkcolor ~sender = unpack_pgm_getbkcolor (sender ~msg:pack_pgm_getbkcolor)

let pgm_getborder = pgm_first + 7
let pack_pgm_getborder = pack_simple_message ~id:pgm_getborder
external unpack_pgm_getborder : message_result -> int = "unpack_pgm_getborder"
let issue_pgm_getborder ~sender = unpack_pgm_getborder (sender ~msg:pack_pgm_getborder)

let pgm_getbuttonsize = pgm_first + 11
let pack_pgm_getbuttonsize = pack_simple_message ~id:pgm_getbuttonsize
external unpack_pgm_getbuttonsize : message_result -> int = "unpack_pgm_getbuttonsize"
let issue_pgm_getbuttonsize ~sender = unpack_pgm_getbuttonsize (sender ~msg:pack_pgm_getbuttonsize)

let pgm_getbuttonstate = pgm_first + 12
type pager_button =
    PGB_BOTTOMORRIGHT
  | PGB_TOPORLEFT
type pager_button_state =
    PGF_DEPRESSED
  | PGF_GRAYED
  | PGF_HOT
  | PGF_INVISIBLE
  | PGF_NORMAL
external pack_pgm_getbuttonstate : which:pager_button -> message_contents = "pack_pgm_getbuttonstate"
external unpack_pgm_getbuttonstate : message_result -> pager_button_state = "unpack_pgm_getbuttonstate"
let issue_pgm_getbuttonstate ~sender ~which = unpack_pgm_getbuttonstate (sender ~msg:(pack_pgm_getbuttonstate ~which))

let pgm_getdroptarget = ccm_first + 4
(* ... *)

let pgm_getpos = pgm_first + 9
let pack_pgm_getpos = pack_simple_message ~id:pgm_getpos
external unpack_pgm_getpos : message_result -> int = "unpack_pgm_getpos"
let issue_pgm_getpos ~sender = unpack_pgm_getpos (sender ~msg:pack_pgm_getpos)

let pgm_recalcsize = pgm_first + 2
let pack_pgm_recalcsize = pack_simple_message ~id:pgm_recalcsize
let unpack_pgm_recalcsize = ignore
let issue_pgm_recalcsize ~sender = unpack_pgm_recalcsize (sender ~msg:pack_pgm_recalcsize)

let pgm_setbkcolor = pgm_first + 4
external pack_pgm_setbkcolor : color:color -> message_contents = "pack_pgm_setbkcolor"
external unpack_pgm_setbkcolor : message_result -> color = "unpack_pgm_setbkcolor"
let issue_pgm_setbkcolor ~sender ~color = unpack_pgm_setbkcolor (sender ~msg:(pack_pgm_setbkcolor ~color))

let pgm_setborder = pgm_first + 6
external pack_pgm_setborder : border:int -> message_contents = "pack_pgm_setborder"
external unpack_pgm_setborder : message_result -> int = "unpack_pgm_setborder"
let issue_pgm_setborder ~sender ~border = unpack_pgm_setborder (sender ~msg:(pack_pgm_setborder ~border))

let pgm_setbuttonsize = pgm_first + 10
external pack_pgm_setbuttonsize : size:int -> message_contents = "pack_pgm_setbuttonsize"
external unpack_pgm_setbuttonsize : message_result -> int = "unpack_pgm_setbuttonsize"
let issue_pgm_setbuttonsize ~sender ~size = unpack_pgm_setbuttonsize (sender ~msg:(pack_pgm_setbuttonsize ~size))

let pgm_setchild = pgm_first + 1
external pack_pgm_setchild : child:hwnd -> message_contents = "pack_pgm_setchild"
let unpack_pgm_setchild = ignore
let issue_pgm_setchild ~sender ~child = unpack_pgm_setchild (sender ~msg:(pack_pgm_setchild ~child))

let pgm_setpos = pgm_first + 8
external pack_pgm_setpos : pos:int -> message_contents = "pack_pgm_setpos"
let unpack_pgm_setpos = ignore
let issue_pgm_setpos ~sender ~pos = unpack_pgm_setpos (sender ~msg:(pack_pgm_setpos ~pos))

(* Notifications *)

type pager_modifier_key =
    PGK_CONTROL
  | PGK_MENU
  | PGK_SHIFT
type pager_scroll_direction =
    PGF_SCROLLDOWN
  | PGF_SCROLLLEFT
  | PGF_SCROLLRIGHT
  | PGF_SCROLLUP
type nmpgscroll = {
    nmpgs_keys : pager_modifier_key list;
    nmpgs_parent_rect : rect;
    nmpgs_dir : pager_scroll_direction;
    nmpgs_pos : point;
    nmpgs_scroll : int }

let pgn_first = -900
let pgn_last = -950

let pgn_calcsize = pgn_first - 2
type pager_dimension =
    PGF_CALCHEIGHT
  | PGF_CALCWIDTH
type pgn_calcsize_handler =
    wnd:hwnd ->
    msg:message_contents ->
    id:int ->
    hdr:nmhdr ->
    which:pager_dimension ->
    int message_handler_result
external on_pgn_calcsize :
    pgn_calcsize_handler ->
    wnd:hwnd ->
    msg:message_contents ->
    message_result option = "on_pgn_calcsize"

let pgn_scroll = pgn_first - 1
external on_pgn_calcsize :
    (nmpgscroll, int) notify_message_handler ->
    wnd:hwnd ->
    msg:message_contents ->
    message_result option = "on_pgn_scroll"
