(* OCaml-Win32
 * win32_toolbar.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: Toolbar Controls *)

let toolbarclassname = "ToolbarWindow32"

type toolbar_extended_style =
    TBSTYLE_EX_DRAWDDARROWS

type toolbar_button_style =
    TBSTYLE_AUTOSIZE
  | TBSTYLE_CHECK
  | TBSTYLE_DROPDOWN
  | TBSTYLE_GROUP
  | TBSTYLE_NOPREFIX
  | TBSTYLE_SEP

type toolbar_button_state =
    TBSTATE_CHECKED
  | TBSTATE_ELLIPSES
  | TBSTATE_ENABLED
  | TBSTATE_HIDDEN
  | TBSTATE_INDETERMINATE
  | TBSTATE_MARKED
  | TBSTATE_PRESSED
  | TBSTATE_WRAP

type tbbutton = {
    tbb_bitmap : int;
    tbb_id : int;
    tbb_state : toolbar_button_state list;
    tbb_style : toolbar_button_style list;
    tbb_data : int32;
    tbb_string : int }

type tbbuttoninfo = {
    tbbi_id : int option;
    tbbi_image : common_control_image_index option;
    tbbi_state : toolbar_button_state list option;
    tbbi_style : toolbar_button_style list option;
    tbbi_size : int option;
    tbbi_lparam : int32 option;
    tbbi_text : string option }
let default_tbbuttoninfo = {
    tbbi_id = None;
    tbbi_image = None;
    tbbi_state = None;
    tbbi_style = None;
    tbbi_size = None;
    tbbi_lparam = None;
    tbbi_text = None }

type tbbuttoninfo_component =
    Tbif_command
  | Tbif_image
  | Tbif_state
  | Tbif_style
  | Tbif_size
  | Tbif_lparam
  | Tbif_text of int
let all_tbbuttoninfo_components = [
    Tbif_command;
    Tbif_image;
    Tbif_state;
    Tbif_style;
    Tbif_size;
    Tbif_lparam;
    Tbif_text 256 ]

type toolbar_standard_bitmap =
    IDB_HIST_LARGE_COLOR
  | IDB_HIST_SMALL_COLOR
  | IDB_STD_LARGE_COLOR
  | IDB_STD_SMALL_COLOR
  | IDB_VIEW_LARGE_COLOR
  | IDB_VIEW_SMALL_COLOR
type toolbar_bitmap_spec =
    Tbbs_standard of toolbar_standard_bitmap
  | Tbbs_resource of hinstance * int
  | Tbbs_bitmap of hbitmap

let std_cut = 0
let std_copy = 1
let std_paste = 2
let std_undo = 3
let std_redow = 4
let std_delete = 5
let std_filenew = 6
let std_fileopen = 7
let std_filesave = 8
let std_printpre = 9
let std_properties = 10
let std_help = 11
let std_find = 12
let std_replace = 13
let std_print = 14
let view_largeicons = 0
let view_smallicons = 1
let view_list = 2
let view_details = 3
let view_sortname = 4
let view_sortsize = 5
let view_sortdate = 6
let view_sorttype = 7
let view_parentfolder = 8
let view_netconnect = 9
let view_netdisconnect = 10
let view_newfolder = 11
let view_viewmenu = 12
let hist_back = 0
let hist_forward = 1
let hist_favorites = 2
let hist_addtofavorites = 3
let hist_viewtree = 4

external create_mapped_bitmap :
    inst:hinstance ->
    id:int ->
    masked:bool ->
    color_maps:(color * color) list option ->
    hbitmap = "create_mapped_bitmap"

external create_toolbar_ex :
    parent:hwnd ->
    style:style ->
    id:int ->
    num_bitmaps:int ->
    bitmap:toolbar_bitmap_spec ->
    buttons:tbbutton list ->
    button_size:size ->
    bitmap_size:size ->
    hwnd = "create_toolbar_ex_bytecode" "create_toolbar_ex_native"

(* Styles *)

type toolbar_style_option =
    TBSTYLE_ALTDRAG
  | TBSTYLE_CUSTOMERASE
  | TBSTYLE_FLAT
  | TBSTYLE_LIST
  | TBSTYLE_REGISTERDROP
  | TBSTYLE_TOOLTIPS
  | TBSTYLE_TRANSPARENT
  | TBSTYLE_WRAPABLE

external toolbar_style_of_option : toolbar_style_option -> style = "toolbar_style_of_option"

let toolbar_style_of_options = special_common_control_style_of_options ~special_func:toolbar_style_of_option

(* Messages *)

let tb_addbitmap = wm_user + 19
external issue_tb_addbitmap : sender:message_sender -> num_bitmaps:int -> bitmap:toolbar_bitmap_spec -> int = "issue_tb_addbitmap"

let tb_addbuttons = wm_user + 20
external issue_tb_addbuttons : sender:message_sender -> buttons:tbbutton list -> unit = "issue_tb_addbuttons"

let tb_addstring = wm_user + 28
external pack_tb_addstring : inst:hinstance -> id:int -> message_contents = "pack_tb_addstring"
external unpack_tb_addstring : message_result -> int = "unpack_tb_addstring"
let issue_tb_addstring ~sender ~inst ~id = unpack_tb_addstring (sender ~msg:(pack_tb_addstring ~inst ~id))
external issue_tb_addstring_direct : sender:message_sender -> strings:string list -> int = "issue_tb_addstring_direct"

let tb_autosize = wm_user + 33
let pack_tb_autosize = pack_simple_message ~id:tb_autosize
let unpack_tb_autosize = ignore
let issue_tb_autosize ~sender = unpack_tb_autosize (sender ~msg:pack_tb_autosize)

let tb_buttoncount = wm_user + 24
let pack_tb_buttoncount = pack_simple_message ~id:tb_buttoncount
external unpack_tb_buttoncount : message_result -> int = "unpack_tb_buttoncount"
let issue_tb_buttoncount ~sender = unpack_tb_buttoncount (sender ~msg:pack_tb_buttoncount)

let tb_buttonstructsize = wm_user + 30
external pack_tb_buttonstructsize : unit -> message_contents = "pack_tb_buttonstructsize"
let unpack_tb_buttonstructsize = ignore
let issue_tb_buttonstructsize ~sender = unpack_tb_buttonstructsize (sender ~msg:(pack_tb_buttonstructsize ()))

let tb_changebitmap = wm_user + 43
external pack_tb_changebitmap : button_id:int -> bitmap:int -> message_contents = "pack_tb_changebitmap"
external unpack_tb_changebitmap : message_result -> unit = "unpack_tb_changebitmap"
let issue_tb_changebitmap ~sender ~button_id ~bitmap = unpack_tb_changebitmap (sender ~msg:(pack_tb_changebitmap ~button_id ~bitmap))

let tb_checkbutton = wm_user + 2
external pack_tb_checkbutton : button_id:int -> check:bool -> message_contents = "pack_tb_checkbutton"
external unpack_tb_checkbutton : message_result -> unit = "unpack_tb_checkbutton"
let issue_tb_checkbutton ~sender ~button_id ~check = unpack_tb_checkbutton (sender ~msg:(pack_tb_checkbutton ~button_id ~check))

let tb_commandtoindex = wm_user + 25
external pack_tb_commandtoindex : button_id:int -> message_contents = "pack_tb_commandtoindex"
external unpack_tb_commandtoindex : message_result -> int = "unpack_tb_commandtoindex"
let issue_tb_commandtoindex ~sender ~button_id = unpack_tb_commandtoindex (sender ~msg:(pack_tb_commandtoindex ~button_id))

let tb_customize = wm_user + 27
let pack_tb_customize = pack_simple_message ~id:tb_customize
let unpack_tb_customize = ignore
let issue_tb_customize ~sender = unpack_tb_customize (sender ~msg:pack_tb_customize)

let tb_deletebutton = wm_user + 22
external pack_tb_deletebutton : button_id:int -> message_contents = "pack_tb_deletebutton"
external unpack_tb_deletebutton : message_result -> unit = "unpack_tb_deletebutton"
let issue_tb_deletebutton ~sender ~button_id = unpack_tb_deletebutton (sender ~msg:(pack_tb_deletebutton ~button_id))

let tb_enablebutton = wm_user + 1
external pack_tb_enablebutton : button_id:int -> enable:bool -> message_contents = "pack_tb_enablebutton"
external unpack_tb_enablebutton : message_result -> unit = "unpack_tb_enablebutton"
let issue_tb_enablebutton ~sender ~button_id ~enable = unpack_tb_enablebutton (sender ~msg:(pack_tb_enablebutton ~button_id ~enable))

let tb_getanchorhighlight = wm_user + 74
let pack_tb_getanchorhighlight = pack_simple_message ~id:tb_getanchorhighlight
external unpack_tb_getanchorhighlight : message_result -> bool = "unpack_tb_getanchorhighlight"
let issue_tb_getanchorhighlight ~sender = unpack_tb_getanchorhighlight (sender ~msg:pack_tb_getanchorhighlight)

let tb_getbitmap = wm_user + 44
external pack_tb_getbitmap : button_id:int -> message_contents = "pack_tb_getbitmap"
external unpack_tb_getbitmap : message_result -> int = "unpack_tb_getbitmap"
let issue_tb_getbitmap ~sender ~button_id = unpack_tb_getbitmap (sender ~msg:(pack_tb_getbitmap ~button_id))

let tb_getbitmapflags = wm_user + 41
let pack_tb_getbitmapflags = pack_simple_message ~id:tb_getbitmapflags
external unpack_tb_getbitmapflags : message_result -> bool = "unpack_tb_getbitmapflags"
let issue_tb_getbitmapflags ~sender = unpack_tb_getbitmapflags (sender ~msg:pack_tb_getbitmapflags)

let tb_getbutton = wm_user + 23
external issue_tb_getbutton : sender:message_sender -> button:int -> tbbutton = "issue_tb_getbutton"

let tb_getbuttoninfo = wm_user + 65
external issue_tb_getbuttoninfo : sender:message_sender -> id:int -> mask:tbbuttoninfo_component list -> tbbuttoninfo * int = "issue_tb_getbuttoninfo"

let tb_getbuttonsize = wm_user + 58
let pack_tb_getbuttonsize = pack_simple_message ~id:tb_getbuttonsize
external unpack_tb_getbuttonsize : message_result -> size = "unpack_tb_getbuttonsize"
let issue_tb_getbuttonsize ~sender = unpack_tb_getbuttonsize (sender ~msg:pack_tb_getbuttonsize)

let tb_getbuttontext = wm_user + 45
external issue_tb_getbuttontext : sender:message_sender -> id:int -> max_length:int -> string = "issue_tb_getbuttontext"

let tb_getcolorscheme = ccm_first + 3
external issue_tb_getcolorscheme : sender:message_sender -> colorscheme = "issue_tb_getcolorscheme"

let tb_getdisabledimagelist = wm_user + 55
let pack_tb_getdisabledimagelist = pack_simple_message ~id:tb_getdisabledimagelist
external unpack_tb_getdisabledimagelist : message_result -> himagelist = "unpack_tb_getdisabledimagelist"
let issue_tb_getdisabledimagelist ~sender = unpack_tb_getdisabledimagelist (sender ~msg:pack_tb_getdisabledimagelist)

let tb_getextendedstyle = wm_user + 85
let pack_tb_getextendedstyle = pack_simple_message ~id:tb_getextendedstyle
external unpack_tb_getextendedstyle : message_result -> toolbar_extended_style list = "unpack_tb_getextendedstyle"
let issue_tb_getextendedstyle ~sender = unpack_tb_getextendedstyle (sender ~msg:pack_tb_getextendedstyle)

let tb_gethotimagelist = wm_user + 53
let pack_tb_gethotimagelist = pack_simple_message ~id:tb_gethotimagelist
external unpack_tb_gethotimagelist : message_result -> himagelist = "unpack_tb_gethotimagelist"
let issue_tb_gethotimagelist ~sender = unpack_tb_gethotimagelist (sender ~msg:pack_tb_gethotimagelist)

let tb_gethotitem = wm_user + 71
let pack_tb_gethotitem = pack_simple_message ~id:tb_gethotitem
external unpack_tb_gethotitem : message_result -> int = "unpack_tb_gethotitem"
let issue_tb_gethotitem ~sender = unpack_tb_gethotitem (sender ~msg:pack_tb_gethotitem)

let tb_getimagelist = wm_user + 49
let pack_tb_getimagelist = pack_simple_message ~id:tb_getimagelist
external unpack_tb_getimagelist : message_result -> himagelist = "unpack_tb_getimagelist"
let issue_tb_getimagelist ~sender = unpack_tb_getimagelist (sender ~msg:pack_tb_getimagelist)

let tb_getinsertmark = wm_user + 79
(* ... *)

let tb_getinsertmarkcolor = wm_user + 89
let pack_tb_getinsertmarkcolor = pack_simple_message ~id:tb_getinsertmarkcolor
external unpack_tb_getinsertmarkcolor : message_result -> color = "unpack_tb_getinsertmarkcolor"
let issue_tb_getinsertmarkcolor ~sender = unpack_tb_getinsertmarkcolor (sender ~msg:pack_tb_getinsertmarkcolor)

let tb_getitemrect = wm_user + 29
external issue_tb_getitemrect : sender:message_sender -> button:int -> rect = "issue_tb_getitemrect"

let tb_getmaxsize = wm_user + 83
external issue_tb_getmaxsize : sender:message_sender -> size = "issue_tb_getmaxsize"

let tb_getobject = wm_user + 62
(* ... *)

let tb_getpadding = wm_user + 86
let pack_tb_getpadding = pack_simple_message ~id:tb_getpadding
external unpack_tb_getpadding : message_result -> size = "unpack_tb_getpadding"
let issue_tb_getpadding ~sender = unpack_tb_getpadding (sender ~msg:pack_tb_getpadding)

let tb_getrect = wm_user + 51
external issue_tb_getrect : sender:message_sender -> id:int -> rect = "issue_tb_getrect"

let tb_getrows = wm_user + 40
let pack_tb_getrows = pack_simple_message ~id:tb_getrows
external unpack_tb_getrows : message_result -> int = "unpack_tb_getrows"
let issue_tb_getrows ~sender = unpack_tb_getrows (sender ~msg:pack_tb_getrows)

let tb_getstate = wm_user + 18
external pack_tb_getstate : id:int -> message_contents = "pack_tb_getstate"
external unpack_tb_getstate : message_result -> toolbar_button_state list = "unpack_tb_getstate"
let issue_tb_getstate ~sender ~id = unpack_tb_getstate (sender ~msg:(pack_tb_getstate ~id))

let tb_getstyle = wm_user + 57
let pack_tb_getstyle = pack_simple_message ~id:tb_getstyle
external unpack_tb_getstyle : message_result -> style = "unpack_tb_getstyle"
let issue_tb_getstyle ~sender = unpack_tb_getstyle (sender ~msg:pack_tb_getstyle)

let tb_gettextrows = wm_user + 61
let pack_tb_gettextrows = pack_simple_message ~id:tb_gettextrows
external unpack_tb_gettextrows : message_result -> int = "unpack_tb_gettextrows"
let issue_tb_gettextrows ~sender = unpack_tb_gettextrows (sender ~msg:pack_tb_gettextrows)

let tb_gettooltips = wm_user + 35
let pack_tb_gettooltips = pack_simple_message ~id:tb_gettooltips
external unpack_tb_gettooltips : message_result -> hwnd = "unpack_tb_gettooltips"
let issue_tb_gettooltips ~sender = unpack_tb_gettooltips (sender ~msg:pack_tb_gettooltips)

(* tb_getunicodeformat: use ccm_getunicodeformat *)

let tb_hidebutton = wm_user + 4
external pack_tb_hidebutton : id:int -> hide:bool -> message_contents = "pack_tb_hidebutton"
external unpack_tb_hidebutton : message_result -> unit = "unpack_tb_hidebutton"
let issue_tb_hidebutton ~sender ~id ~hide = unpack_tb_hidebutton (sender ~msg:(pack_tb_hidebutton ~id ~hide))

let tb_hittest = wm_user + 69
type toolbar_hittest_result =
    Tbhtr_on_button of int
  | Tbhtr_other of int
external issue_tb_hittest : sender:message_sender -> pt:point -> toolbar_hittest_result = "issue_tb_hittest"

let tb_indeterminate = wm_user + 5
external pack_tb_indeterminate : id:int -> indeterminate:bool -> message_contents = "pack_tb_indeterminate"
external unpack_tb_indeterminate : message_result -> unit = "unpack_tb_indeterminate"
let issue_tb_indeterminate ~sender ~id ~indeterminate = unpack_tb_indeterminate (sender ~msg:(pack_tb_indeterminate ~id ~indeterminate))

let tb_insertbutton = wm_user + 21
external issue_tb_insertbutton : sender:message_sender -> button:int -> tbbutton:tbbutton -> unit = "issue_tb_insertbutton"

let tb_insertmarkhittest = wm_user + 81
(* ... *)

let tb_isbuttonchecked = wm_user + 10
external pack_tb_isbuttonchecked : id:int -> message_contents = "pack_tb_isbuttonchecked"
external unpack_tb_isbuttonchecked : message_result -> bool = "unpack_tb_isbuttonchecked"
let issue_tb_isbuttonchecked ~sender ~id = unpack_tb_isbuttonchecked (sender ~msg:(pack_tb_isbuttonchecked ~id))

let tb_isbuttonenabled = wm_user + 10
external pack_tb_isbuttonenabled : id:int -> message_contents = "pack_tb_isbuttonenabled"
external unpack_tb_isbuttonenabled : message_result -> bool = "unpack_tb_isbuttonenabled"
let issue_tb_isbuttonenabled ~sender ~id = unpack_tb_isbuttonenabled (sender ~msg:(pack_tb_isbuttonenabled ~id))

let tb_isbuttonhidden = wm_user + 10
external pack_tb_isbuttonhidden : id:int -> message_contents = "pack_tb_isbuttonhidden"
external unpack_tb_isbuttonhidden : message_result -> bool = "unpack_tb_isbuttonhidden"
let issue_tb_isbuttonhidden ~sender ~id = unpack_tb_isbuttonhidden (sender ~msg:(pack_tb_isbuttonhidden ~id))

let tb_isbuttonhighlighted = wm_user + 10
external pack_tb_isbuttonhighlighted : id:int -> message_contents = "pack_tb_isbuttonhighlighted"
external unpack_tb_isbuttonhighlighted : message_result -> bool = "unpack_tb_isbuttonhighlighted"
let issue_tb_isbuttonhighlighted ~sender ~id = unpack_tb_isbuttonhighlighted (sender ~msg:(pack_tb_isbuttonhighlighted ~id))

let tb_isbuttonindeterminate = wm_user + 10
external pack_tb_isbuttonindeterminate : id:int -> message_contents = "pack_tb_isbuttonindeterminate"
external unpack_tb_isbuttonindeterminate : message_result -> bool = "unpack_tb_isbuttonindeterminate"
let issue_tb_isbuttonindeterminate ~sender ~id = unpack_tb_isbuttonindeterminate (sender ~msg:(pack_tb_isbuttonindeterminate ~id))

let tb_isbuttonpressed = wm_user + 10
external pack_tb_isbuttonpressed : id:int -> message_contents = "pack_tb_isbuttonpressed"
external unpack_tb_isbuttonpressed : message_result -> bool = "unpack_tb_isbuttonpressed"
let issue_tb_isbuttonpressed ~sender ~id = unpack_tb_isbuttonpressed (sender ~msg:(pack_tb_isbuttonpressed ~id))

let tb_loadimages = wm_user + 50
external pack_tb_loadimages : bitmap:toolbar_bitmap_spec -> message_contents = "pack_tb_loadimages"
external unpack_tb_loadimages : message_result -> int = "unpack_tb_loadimages"
let issue_tb_loadimages ~sender ~bitmap = unpack_tb_loadimages (sender ~msg:(pack_tb_loadimages ~bitmap))

let tb_mapaccelerator = wm_user + 78
external issue_tb_mapaccelerator : sender:message_sender -> char:char -> int = "issue_tb_mapaccelerator"

let tb_markbutton = wm_user + 6
external pack_tb_markbutton : id:int -> highlight:bool -> message_contents = "pack_tb_markbutton"
external unpack_tb_markbutton : message_result -> unit = "unpack_tb_markbutton"
let issue_tb_markbutton ~sender ~id ~highlight = unpack_tb_markbutton (sender ~msg:(pack_tb_markbutton ~id ~highlight))

let tb_movebutton = wm_user + 82
external pack_tb_movebutton : old_pos:int -> new_pos:int -> message_contents = "pack_tb_movebutton"
external unpack_tb_movebutton : message_result -> unit = "unpack_tb_movebutton"
let issue_tb_movebutton ~sender ~old_pos ~new_pos = unpack_tb_movebutton (sender ~msg:(pack_tb_movebutton ~old_pos ~new_pos))

let tb_pressbutton = wm_user + 3
external pack_tb_pressbutton : id:int -> press:bool -> message_contents = "pack_tb_pressbutton"
external unpack_tb_pressbutton : message_result -> unit = "unpack_tb_pressbutton"
let issue_tb_pressbutton ~sender ~id ~press = unpack_tb_pressbutton (sender ~msg:(pack_tb_pressbutton ~id ~press))

let tb_replacebitmap = wm_user + 46
type tbreplacebitmap = {
    tbrb_old : toolbar_bitmap_spec;
    tbrb_new : toolbar_bitmap_spec;
    tbrb_num_buttons : int }
external issue_tb_replacebitmap : sender:message_sender -> tbreplacebitmap:tbreplacebitmap -> unit = "issue_tb_replacebitmap"

let tb_saverestore = wm_user + 26
type tbsaveparams = {
    tbsp_key : hkey;
    tbsp_sub_key : string;
    tbsp_value_name : string }
external issue_tb_saverestore : sender:message_sender -> save:bool -> tbsaveparams:tbsaveparams -> unit = "issue_tb_saverestore"

let tb_setanchorhighlight = wm_user + 73
external pack_tb_setanchorhighlight : anchor:bool -> message_contents = "pack_tb_setanchorhighlight"
external unpack_tb_setanchorhighlight : message_result -> bool = "unpack_tb_setanchorhighlight"
let issue_tb_setanchorhighlight ~sender ~anchor = unpack_tb_setanchorhighlight (sender ~msg:(pack_tb_setanchorhighlight ~anchor))

let tb_setbitmapsize = wm_user + 32
external pack_tb_setbitmapsize : size:size -> message_contents = "pack_tb_setbitmapsize"
external unpack_tb_setbitmapsize : message_result -> unit = "unpack_tb_setbitmapsize"
let issue_tb_setbitmapsize ~sender ~size = unpack_tb_setbitmapsize (sender ~msg:(pack_tb_setbitmapsize ~size))

let tb_setbuttoninfo = wm_user + 66
external issue_tb_setbuttoninfo : sender:message_sender -> id:int -> info:tbbuttoninfo -> unit = "issue_tb_setbuttoninfo"

let tb_setbuttonsize = wm_user + 31
external pack_tb_setbuttonsize : size:size -> message_contents = "pack_tb_setbuttonsize"
external unpack_tb_setbuttonsize : message_result -> unit = "unpack_tb_setbuttonsize"
let issue_tb_setbuttonsize ~sender ~size = unpack_tb_setbuttonsize (sender ~msg:(pack_tb_setbuttonsize ~size))

let tb_setbuttonwidth = wm_user + 59
external pack_tb_setbuttonwidth : min:int -> max:int -> message_contents = "pack_tb_setbuttonwidth"
external unpack_tb_setbuttonwidth : message_result -> unit = "unpack_tb_setbuttonwidth"
let issue_tb_setbuttonwidth ~sender ~min ~max = unpack_tb_setbuttonwidth (sender ~msg:(pack_tb_setbuttonwidth ~min ~max))

let tb_setcmdid = wm_user + 42
external pack_tb_setcmdid : button:int -> id:int -> message_contents = "pack_tb_setcmdid"
external unpack_tb_setcmdid : message_result -> unit = "unpack_tb_setcmdid"
let issue_tb_setcmdid ~sender ~button ~id = unpack_tb_setcmdid (sender ~msg:(pack_tb_setcmdid ~button ~id))

let tb_setcolorscheme = ccm_first + 2
external issue_tb_setcolorscheme : sender:message_sender -> cs:colorscheme -> unit = "issue_tb_setcolorscheme"

let tb_setdisabledimagelist = wm_user + 54
external pack_tb_setdisabledimagelist : iml:himagelist -> message_contents = "pack_tb_setdisabledimagelist"
external unpack_tb_setdisabledimagelist : message_result -> himagelist = "unpack_tb_setdisabledimagelist"
let issue_tb_setdisabledimagelist ~sender ~iml = unpack_tb_setdisabledimagelist (sender ~msg:(pack_tb_setdisabledimagelist ~iml))

let tb_setdrawtextflags = wm_user + 70
(* ... *)

let tb_setextendedstyle = wm_user + 84
external pack_tb_setextendedstyle : style:toolbar_extended_style list -> message_contents = "pack_tb_setextendedstyle"
external unpack_tb_setextendedstyle : message_result -> toolbar_extended_style list = "unpack_tb_setextendedstyle"
let issue_tb_setextendedstyle ~sender ~style = unpack_tb_setextendedstyle (sender ~msg:(pack_tb_setextendedstyle ~style))

let tb_sethotimagelist = wm_user + 52
external pack_tb_sethotimagelist : iml:himagelist -> message_contents = "pack_tb_sethotimagelist"
external unpack_tb_sethotimagelist : message_result -> himagelist = "unpack_tb_sethotimagelist"
let issue_tb_sethotimagelist ~sender ~iml = unpack_tb_sethotimagelist (sender ~msg:(pack_tb_sethotimagelist ~iml))

let tb_sethotitem = wm_user + 72
external pack_tb_sethotitem : item:int -> message_contents = "pack_tb_sethotitem"
external unpack_tb_sethotitem : message_result -> int = "unpack_tb_sethotitem"
let issue_tb_sethotitem ~sender ~item = unpack_tb_sethotitem (sender ~msg:(pack_tb_sethotitem ~item))

let tb_setimagelist = wm_user + 48
external pack_tb_setimagelist : iml:himagelist -> message_contents = "pack_tb_setimagelist"
external unpack_tb_setimagelist : message_result -> himagelist = "unpack_tb_setimagelist"
let issue_tb_setimagelist ~sender ~iml = unpack_tb_setimagelist (sender ~msg:(pack_tb_setimagelist ~iml))

let tb_setindent = wm_user + 47
external pack_tb_setindent : indent:int -> message_contents = "pack_tb_setindent"
external unpack_tb_setindent : message_result -> unit = "unpack_tb_setindent"
let issue_tb_setindent ~sender ~indent = unpack_tb_setindent (sender ~msg:(pack_tb_setindent ~indent))

let tb_setinsertmark = wm_user + 80
(* ... *)

let tb_setinsertmarkcolor = wm_user + 88
external pack_tb_setinsertmarkcolor : color:color -> message_contents = "pack_tb_setinsertmarkcolor"
external unpack_tb_setinsertmarkcolor : message_result -> color = "unpack_tb_setinsertmarkcolor"
let issue_tb_setinsertmarkcolor ~sender ~color = unpack_tb_setinsertmarkcolor (sender ~msg:(pack_tb_setinsertmarkcolor ~color))

let tb_setmaxtextrows = wm_user + 60
external pack_tb_setmaxtextrows : rows:int -> message_contents = "pack_tb_setmaxtextrows"
external unpack_tb_setmaxtextrows : message_result -> unit = "unpack_tb_setmaxtextrows"
let issue_tb_setmaxtextrows ~sender ~rows = unpack_tb_setmaxtextrows (sender ~msg:(pack_tb_setmaxtextrows ~rows))

let tb_setpadding = wm_user + 87
external pack_tb_setpadding : padding:size -> message_contents = "pack_tb_setpadding"
external unpack_tb_setpadding : message_result -> size = "unpack_tb_setpadding"
let issue_tb_setpadding ~sender = unpack_tb_setpadding (sender ~msg:pack_tb_setpadding)

let tb_setparent = wm_user + 37
external pack_tb_setparent : parent:hwnd -> message_contents = "pack_tb_setparent"
external unpack_tb_setparent : message_result -> hwnd = "unpack_tb_setparent"
let issue_tb_setparent ~sender ~parent = unpack_tb_setparent (sender ~msg:(pack_tb_setparent ~parent))

let tb_setrows = wm_user + 39
external issue_tb_setrows : sender:message_sender -> rows:int -> larger:bool -> rect = "issue_tb_setrows"

let tb_setstate = wm_user + 17
external pack_tb_setstate : id:int -> state:toolbar_button_state list -> message_contents = "pack_tb_setstate"
external unpack_tb_setstate : message_result -> unit = "unpack_tb_setstate"
let issue_tb_setstate ~sender ~id ~state = unpack_tb_setstate (sender ~msg:(pack_tb_setstate ~id ~state))

let tb_setstyle = wm_user + 56
external pack_tb_setstyle : style:style -> message_contents = "pack_tb_setstyle"
let unpack_tb_setstyle = ignore
let issue_tb_setstyle ~sender ~style = unpack_tb_setstyle (sender ~msg:(pack_tb_setstyle ~style))

let tb_settooltips = wm_user + 36
external pack_tb_settooltips : tooltips:hwnd -> message_contents = "pack_tb_settooltips"
let unpack_tb_settooltips = ignore
let issue_tb_settooltips ~sender ~tooltips = unpack_tb_settooltips (sender ~msg:(pack_tb_settooltips ~tooltips))

(* tb_setunicodeformat: use ccm_setunicodeformat *)

(* Notifications *)

type nmtbcustomdraw = {
    nmtbcd_item_spec : int;
    nmtbcd_mono_dither_brush : hbrush;
    nmtbcd_lines_brush : hbrush;
    nmtbcd_lines_pen : hpen;
    nmtbcd_text_color : color;
    nmtbcd_mark_color : color;
    nmtbcd_text_highlight_color : color;
    nmtbcd_btn_face_color : color;
    nmtbcd_btn_highlight_color : color;
    nmtbcd_highlight_hot_track_color : color;
    nmtbcd_text_rect : rect;
    nmtbcd_string_bk_mode : background_mode;
    nmtbcd_hl_string_bk_mode : background_mode }
external unpack_nmtbcustomdraw : msg:message_contents -> nmtbcustomdraw = "unpack_nmtbcustomdraw"

type nmtoolbar = {
    nmtb_item : int }
external unpack_nmtoolbar : msg:message_contents -> nmtoolbar = "unpack_nmtoolbar"

type nmtoolbar_querying = {
    nmtbq_item : int;
    nmtbq_tbbutton : tbbutton }
external unpack_nmtoolbar_querying : msg:message_contents -> nmtoolbar_querying = "unpack_nmtoolbar_querying"

type nmtbhotitem_reason =
    HICF_ACCELERATOR
  | HICF_ARROWKEYS
  | HICF_DUPACCEL
  | HICF_ENTERING
  | HICF_LEAVING
  | HICF_MOUSE
  | HICF_OTHER
  | HICF_RESELECT
type nmtbhotitem = {
    nmtbhi_old : int;
    nmtbhi_new : int;
    nmtbhi_flags : nmtbhotitem_reason list }
external unpack_nmtbhotitem : msg:message_contents -> nmtbhotitem = "unpack_nmtbhotitem"

let tbn_first = -700
let tbn_last = -720

let tbn_beginadjust = tbn_first - 3
let on_tbn_beginadjust = on_notify_message ~code:tbn_beginadjust ~unpack:unpack_simple_notify ~return:return_simple_message

let tbn_begindrag = tbn_first - 1
let on_tbn_begindrag = on_notify_message ~code:tbn_begindrag ~unpack:unpack_nmtoolbar ~return:return_simple_message

let tbn_custhelp = tbn_first - 9
let on_tbn_custhelp = on_notify_message ~code:tbn_custhelp ~unpack:unpack_simple_notify ~return:return_simple_message

let tbn_deletingbutton = tbn_first - 15
let on_tbn_deletingbutton = on_notify_message ~code:tbn_deletingbutton ~unpack:unpack_nmtoolbar ~return:return_simple_message

let tbn_dragout = tbn_first - 14
let on_tbn_dragout = on_notify_message ~code:tbn_dragout ~unpack:unpack_nmtoolbar ~return:return_simple_message

let tbn_dropdown = tbn_first - 10
type tbn_dropdown_result =
    TBDDRET_DEFAULT
  | TBDDRET_NODEFAULT
  | TBDDRET_TREATPRESSED
external return_tbn_dropdown : result:tbn_dropdown_result -> message_result = "return_tbn_dropdown"
let on_tbn_dropdown = on_notify_message ~code:tbn_dropdown ~unpack:unpack_nmtoolbar ~return:return_tbn_dropdown

let tbn_endadjust = tbn_first - 4
let on_tbn_endadjust = on_notify_message ~code:tbn_endadjust ~unpack:unpack_simple_notify ~return:return_simple_message

let tbn_enddrag = tbn_first - 2
let on_tbn_enddrag = on_notify_message ~code:tbn_enddrag ~unpack:unpack_nmtoolbar ~return:return_simple_message

let tbn_getbuttoninfo = tbn_first - 0
type tbn_getbuttoninfo_handler =
    wnd:hwnd ->
    msg:message_contents ->
    id:int ->
    hdr:nmhdr ->
    item:int ->
    max_length:int ->
    string option message_handler_result
external on_tbn_getbuttoninfo :
    tbn_getbuttoninfo_handler ->
    wnd:hwnd ->
    msg:message_contents ->
    message_result option = "on_tbn_getbuttoninfo"

let tbn_getdispinfo = tbn_first - 16
type toolbar_dispinfo = {
    tbdi_image : int option;
    tbdi_text : string option }
let default_toolbar_dispinfo = {
    tbdi_image = None;
    tbdi_text = None }
type toolbar_dispinfo_component =
    Tbnf_image
  | Tbnf_text of int
type tbn_getdispinfo_handler =
    wnd:hwnd ->
    msg:message_contents ->
    id:int ->
    hdr:nmhdr ->
    mask:toolbar_dispinfo_component list ->
    item_id:int ->
    lparam:int32 ->
    (toolbar_dispinfo * bool) message_handler_result
external on_tbn_getdispinfo :
    tbn_getdispinfo_handler ->
    wnd:hwnd ->
    msg:message_contents ->
    message_result option = "on_tbn_getdispinfo"

let tbn_getinfotip = tbn_first - 18
type tbn_getinfotip_handler =
    wnd:hwnd ->
    msg:message_contents ->
    id:int ->
    hdr:nmhdr ->
    max_length:int ->
    item:int ->
    lparam:int32 ->
    string message_handler_result
external on_tbn_getinfotip :
    tbn_getinfotip_handler ->
    wnd:hwnd ->
    msg:message_contents ->
    message_result option = "on_tbn_getinfotip"

let tbn_getobject = tbn_first - 12
(* ... *)

let tbn_hotitemchange = tbn_first - 13
let on_tbn_hotitemchange = on_notify_message ~code:tbn_hotitemchange ~unpack:unpack_nmtbhotitem ~return:return_common_notify

let tbn_querydelete = tbn_first - 7
external return_tbn_querydelete : result:bool -> message_result = "return_tbn_querydelete"
let on_tbn_querydelete = on_notify_message ~code:tbn_querydelete ~unpack:unpack_nmtoolbar_querying ~return:return_tbn_querydelete

let tbn_queryinsert = tbn_first - 6
external return_tbn_queryinsert : result:bool -> message_result = "return_tbn_queryinsert"
let on_tbn_queryinsert = on_notify_message ~code:tbn_queryinsert ~unpack:unpack_nmtoolbar_querying ~return:return_tbn_queryinsert

let tbn_reset = tbn_first - 5
let on_tbn_reset = on_notify_message ~code:tbn_reset ~unpack:unpack_simple_notify ~return:return_simple_message

let tbn_toolbarchange = tbn_first - 8
let on_tbn_toolbarchange = on_notify_message ~code:tbn_toolbarchange ~unpack:unpack_simple_notify ~return:return_simple_message
