# IupGetParam: Example
#  Shows a dialog with all the possible fields. 

module getparam_

using Printf
using IUP

export
    getparam

#------------------------example html/examples/C/getparam.c ----------------------------------
function param_action end
param_action_c = @cfunction(param_action, Cint, (Ptr{Ihandle}, Int, Ptr{Cvoid}))

function getparam()

    pboolean::Cint = 1
    pinteger::Cint = 3456
    preal::Float32 = 3.543
    pinteger2::Cint = 192
    preal2::Float32 = 0.5
    pangle::Float32 = 90
    pstring = "string text"
    pcolor = "255 0 128"
    plist::Cint = 2
    pstring2 = "second text\nsecond line"
    pfile_name = "test.jpg"

    IupOpen()                       #Initializes IUP
    IupControlsOpen()               # so we can show the IupDial, but can be tested without it
    IupSetLanguage("ENGLISH")

    if (IupGetParam("Title", param_action_c, C_NULL,
                   "Boolean: %b[No,Yes]{Boolean Tip}\n
                   Integer: %i{Integer Tip}\n
                   Real 1: %r{Real Tip}\n
                   Sep1 %t\n
                   Integer: %i[0,255]{Integer Tip 2}\n
                   Real 2: %r[-1.5,1.5]{Real Tip 2}\n
                   Sep2 %t\n
                   Angle: %a[0,360]{Angle Tip}\n
                   String: %s{String Tip}\n
                   List: %l|item1|item2|item3|{List Tip}\n
                   File: %f[OPEN|*.bmp;*.jpg|CURRENT|NO|NO]{File Tip}\n
                   Color: %c{Color Tip}\n
                   Sep3 %t\n
                   Multiline: %m{Multiline Tip}\n",
                   Ref(pboolean), Ref(pinteger), Ref(preal), Ref(pinteger2), Ref(preal2),
                   Ref(pangle), pstring, Ref(plist), pfile_name, pcolor, pstring2, C_NULL) != 0)
        return IUP_DEFAULT
    end

    # the float values (Real 1, Real 2 and Angle ) are not displayed correctly.
    IupMessagef("IupGetParam",
              "Boolean Value: %d\n
               Integer: %d\n
               Real 1: %g\n
               Integer: %d\n
               Real 2: %g\n
               Angle: %g\n
               String: %s\n
               List Index: %d\n
               FileName: %s\n
               Color: %s\n
               Multiline: %s",
               pboolean, pinteger, preal, pinteger2, preal2, pangle,
               pstring, plist, pfile_name, pcolor, pstring2)
 
    IupClose()                                  # And close it when ready
end

function param_action(dialog::Ptr{Ihandle}, param_index::Cint, user_data::Ptr{Cvoid})
    if (param_index == IUP_GETPARAM_OK)
        @printf("Button1 (OK)\n");
    elseif (param_index == IUP_GETPARAM_MAP)
        @printf("Map\n")
    elseif (param_index == IUP_GETPARAM_INIT)
        @printf("Init\n")
    elseif (param_index == IUP_GETPARAM_CANCEL)
        @printf("Button2 (Cancel)\n")
    elseif (param_index == IUP_GETPARAM_HELP)
        @printf("Button3 (Help)\n")
    elseif (param_index == IUP_GETPARAM_CLOSE)
        @printf("Close\n")
    else
        param_str = sprintf("PARAM%d", param_index)
        param = convert(Ptr{Ihandle}, IupGetAttribute(dialog, param_str))
        @printf("%s = %s\n", param_str, IupGetAttribute(param, "VALUE"))
    end

    ret::Cint = 1
    return ret
end

end     # module