(* OCaml-Win32
 * win32_ipaddress.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: IP Address Controls *)

let wc_ipaddress = "SysIPAddress32"

type ip_address = int32

external pack_ip_address : (int * int * int * int) -> ip_address = "pack_ip_address"
external unpack_ip_address : ip_address -> (int * int * int * int) = "unpack_ip_address"

(* Messages *)

let ipm_clearaddress = wm_user + 100
let pack_ipm_clearaddress = pack_simple_message ~id:ipm_clearaddress
let unpack_ipm_clearaddress = ignore
let issue_ipm_clearaddress ~sender = unpack_ipm_clearaddress (sender ~msg:pack_ipm_clearaddress)

let ipm_getaddress = wm_user + 102
external issue_ipm_getaddress : sender:message_sender -> (ip_address * int) = "issue_ipm_getaddress"

let ipm_isblank = wm_user + 105
let pack_ipm_isblank = pack_simple_message ~id:ipm_isblank
external unpack_ipm_isblank : message_result -> bool = "unpack_ipm_isblank"
let issue_ipm_isblank ~sender = unpack_ipm_isblank (sender ~msg:pack_ipm_isblank)

let ipm_setaddress = wm_user + 101
external pack_ipm_setaddress : address:ip_address -> message_contents = "pack_ipm_setaddress"
let unpack_ipm_setaddress = ignore
let issue_ipm_setaddress ~sender ~address = unpack_ipm_setaddress (sender ~msg:(pack_ipm_setaddress ~address))

let ipm_setfocus = wm_user + 104
external pack_ipm_setfocus : field:int -> message_contents = "pack_ipm_setfocus"
let unpack_ipm_setfocus = ignore
let issue_ipm_setfocus ~sender ~field = unpack_ipm_setfocus (sender ~msg:(pack_ipm_setfocus ~field))

let ipm_setrange = wm_user + 103
external pack_ipm_setrange : field:int -> range:(int * int) -> message_contents = "pack_ipm_setrange"
external unpack_ipm_setrange : message_result -> unit = "unpack_ipm_setrange"
let issue_ipm_setrange ~sender ~field ~range = unpack_ipm_setrange (sender ~msg:(pack_ipm_setrange ~field ~range))

(* Notifications *)

let ipn_first = -860
let ipn_last = -879

let ipn_fieldchanged = ipn_first - 0
type ipn_fieldchanged_handler =
    wnd:hwnd ->
    msg:message_contents ->
    id:int ->
    hdr:nmhdr ->
    field:int ->
    value:int ->
    int message_handler_result
external on_ipn_fieldchanged :
    ipn_fieldchanged_handler ->
    wnd:hwnd ->
    msg:message_contents ->
    message_result option = "on_ipn_fieldchanged"
