/'
  Program to exemplify the IupVal element.
 '/

#Include once "crt.bi"
#Include once "inc/iup.bi"
#Include once "inc/iupkey.bi"

sub _init_ constructor
  IupOpen(0,0)
end sub

sub _exit_ destructor
  IupClose()
end sub

Dim Shared As Ihandle ptr lbl_h, lbl_v

function spin_cb cdecl(ih As Ihandle ptr , pos_ As Integer )As Integer
  printf(!"SPIN_CB(%d)\n", pos_)
  if (Not IupGetInt(ih, "SPINAUTO")) Then
    IupSetfAttribute(ih, "VALUE", "%s(%d)", "Test", pos_)
  End If
  return IUP_DEFAULT	
End Function

function action_cb cdecl(ih As Ihandle ptr , c As Integer, after As ZString Ptr)As Integer
  printf("ACTION(%d, %s)\n", c, after)
  return IUP_DEFAULT
End Function

function setspinvalue cdecl (ih As Ihandle Ptr)As Integer
  IupSetAttribute(IupGetDialogChild(ih, "spin"), "SPINVALUE", "25")
  return IUP_DEFAULT
End Function

Sub TextSpinTest()
  Dim As Ihandle Ptr dlg, text
  text = IupText(NULL)
  IupSetAttribute(text, "SIZE", "60x")
  IupSetAttribute(text, "SPIN", "YES")
    
'  IupSetAttribute(text, "EXPAND", "HORIZONTAL")
'  IupSetAttribute(text, "SPINMIN", "10")
'  IupSetAttribute(text, "SPINMAX", "60")
'  IupSetAttribute(text, "SPININC", "5")
'  IupSetAttribute(text, "SPINWRAP", "YES")
'  IupSetAttribute(text, "SPINALIGN", "LEFT")
'  IupSetAttribute(text, "SPINVALUE", "25")
'  IupSetAttribute(text, "SPINAUTO", "NO")

  IupSetAttribute(text, "NAME", "spin")
  IupSetCallback(text, "SPIN_CB", cast(Icallback,@spin_cb))
  IupSetCallback(text, "ACTION", cast(Icallback,@action_cb))

  dlg = IupDialog(IupVbox(text, IupButton("SPINVALUE", "setspinvalue"), NULL))
  IupSetAttribute(dlg, "GAP", "20")
  IupSetAttribute(dlg, "MARGIN", "20x20")
'  IupSetAttribute(dlg, "BGCOLOR", "173 177 194") ' Motif BGCOLOR for documentation
  IupSetFunction("setspinvalue", cast(Icallback,@setspinvalue))
  IupSetAttribute(dlg, "TITLE", "Text Spin Test")
  IupShow(dlg)
End Sub

'
' main
'
TextSpinTest()
IupMainLoop()

