'/* IupSubmenu: Example in C 
'   Creates a dialog with a menu with three submenus.
'   One of the submenus has a submenu, which has another submenu.
'*/

'/* ANSI C libraries include */

#Include "crt/stdlib.bi"
#Include "crt/stdio.bi"

#Include "inc/iup.bi"
#Include "inc/iupcd.bi"


sub _init_ constructor
  IupOpen(0,0)
end sub

sub _exit_ destructor
  IupClose()
end sub


'/******************************************************************************
' * Function:                                                                  *
' * Item help callback                                                         *
' *                                                                            *
' * Description:                                                               *
' * Shows a message saying that only Help and Exit items performs an operation *
' *                                                                            *
' * Value returned:                                                            *
' * IUP_DEFAULT                                                                *
' ******************************************************************************/
Function item_help_cb cdecl() As Integer
  IupMessage ("Warning", "Only Help and Exit items performs an operation") 
  return IUP_DEFAULT
End Function


'/******************************************************************************
' * Function:                                                                  *
' * Item exit callback                                                         *
' *                                                                            *
' * Description:                                                               *
' * Exits the program                                                          *
' *                                                                            *
' * Value returned:                                                            *
' * IUP_DEFAULT                                                                *
' ******************************************************************************/
Function item_exit_cb  Cdecl() As Integer
  return IUP_CLOSE
End Function



'/* IUP identifiers */
Dim As Ihandle Ptr dlg,text,menu,menu_file,menu_edit,menu_help,_
menu_create,menu_triangle,submenu_file,submenu_edit,submenu_help,_
submenu_create,submenu_triangle,item_new,item_open,item_close,item_exit,_
item_copy,item_paste,item_line,item_circle,item_equilateral,item_isoceles,_
item_scalenus,item_help



'/* Program begin */
  
'/* Creates a multiline */
text = IupText (NULL)
  
'/* Sets value of the text and turns on expand */ 
IupSetAttributes (text,!"VALUE = \"This text is here only to compose\",EXPAND = YES")
     
  '/* Creates items of menu file */
  item_new = IupItem ("New", NULL)
  item_open = IupItem ("Open", NULL)
  item_close = IupItem ("Close", NULL)
  item_exit = IupItem ("Exit", "item_exit_act")

  '/* Creates items of menu edit */
  item_copy = IupItem ("Copy", NULL)
  item_paste = IupItem ("Paste", NULL)

  '/* Creates items for menu triangle */
  item_scalenus = IupItem ("Scalenus", NULL)
  item_isoceles = IupItem ("Isoceles", NULL)
  item_equilateral = IupItem ("Equilateral", NULL)

  '/* Create menu triangle */
  menu_triangle = IupMenu (item_equilateral, item_isoceles, item_scalenus, NULL)

  '/* Creates submenu triangle */
  submenu_triangle = IupSubmenu ("Triangle", menu_triangle)

  '/* Creates items for menu create */
  item_line = IupItem ("Line", NULL)
  item_circle = IupItem ("Circle", NULL)

  '/* Creates menu create */
  menu_create = IupMenu (item_line, item_circle, submenu_triangle, NULL)

  '/* Creates submenu create */
  submenu_create = IupSubmenu ("Create", menu_create)

  '/* Creates items of menu help */
  item_help = IupItem ("Help", "item_help_act")
  
  '/* Creates three menus */
  menu_file = IupMenu (item_new, item_open, item_close, IupSeparator(), item_exit, NULL)
  menu_edit = IupMenu (item_copy, item_paste, IupSeparator(), submenu_create, NULL)
  menu_help = IupMenu (item_help, NULL)

  '/* Creates three submenus */
  submenu_file = IupSubmenu ("File", menu_file)
  submenu_edit = IupSubmenu ("Edit", menu_edit)
  submenu_help = IupSubmenu ("Help", menu_help)
  
  '/* Creates main menu with file menu */
  menu = IupMenu (submenu_file, submenu_edit, submenu_help, NULL)

  '/* Registers callbacks */
  IupSetCallback (item_help, "ACTION", Cast(Icallback,@item_help_cb)) 
  IupSetCallback (item_exit, "ACTION", Cast(Icallback,@item_exit_cb)) 
 
  '/* Associates handle "menu" with menu */
  IupSetHandle ("menu", menu)
                                
  '/* Creates dialog with a text */
  dlg = IupDialog (text)

  '/* Sets title and size of the dialog and associates a menu to it */
  IupSetAttributes (dlg, !"TITLE=\"IupSubmenu Example\",SIZE=QUARTERxEIGHTH,MENU=menu")

  '/* Shows dialog in the center of the screen */
  IupShowXY (dlg, IUP_CENTER, IUP_CENTER)

  '/* Initializes IUP main loop */
  IupMainLoop ()
  
  '/* Finishes IUP */
  IupClose ()
