$ filename "mdi.exe"
'include "$/inc/RTL32.inc"
include "$/inc/console.inc"
includepath "iup/"
extern lib "IUP/iup.dll" cdecl
include "iup.h"
extern cdecl
function mdi_tilehoriz(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "TILEHORIZONTAL")
return IUP_DEFAULT
end function
function mdi_tilevert(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "TILEVERTICAL")
return IUP_DEFAULT
end function
function mdi_cascade(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "CASCADE")
return IUP_DEFAULT
end function
function mdi_icon(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDIARRANGE", "ICON")
return IUP_DEFAULT
end function
function mdi_next(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDIACTIVATE", "NEXT")
return IUP_DEFAULT
end function
function mdi_previous(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDIACTIVATE", "PREVIOUS")
return IUP_DEFAULT
end function
function mdi_closeall(sys ih)
IupSetAttribute(IupGetDialog(ih), "MDICLOSEALL", NULL)
return IUP_DEFAULT
end function
function mdi_activate(sys ih)
print "mdi_activate " & IupGetName(ih) & cr
return IUP_DEFAULT
end function
function button_cb(sys ih)
print "button_cb()" & cr
return IUP_DEFAULT
end function
function mdi_new(sys ih)
static int id = 0
sys box, txt, dlg, btn
txt = IupText(NULL)
btn = IupButton("Test", NULL)
IupSetCallback(btn,"ACTION", @button_cb)
hbox = IupHbox(btn, NULL)
box = IupVbox(hbox, txt, NULL)
IupSetAttribute(box,"MARGIN","5x5")
dlg = IupDialog(box)
IupSetfAttribute(dlg,"TITLE","MDI Child (%d)", id) : id++
IupSetAttribute(dlg,"MDICHILD","YES")
IupSetAttribute(dlg,"PARENTDIALOG","mdiFrame")
IupSetCallback(dlg,"MDIACTIVATE_CB",@mdi_activate)
IupSetAttribute(dlg,"RASTERSIZE","300x300")
' IupSetAttribute(dlg, "PLACEMENT", "MAXIMIZED")
IupShow(dlg)
IupSetAttribute(dlg,"RASTERSIZE",NULL)
return IUP_DEFAULT
end function
sub createMenu()
sys winmenu, mnu
'create menus, bottom-up from items to sub menu to main menu
items1 = IupMenu(IupItem("New", "mdi_new"), NULL)
submenu1 = IupSubmenu("MDI", items1)
'more then a single item must be splitted
i1=IupItem("Tile Horizontal", "mdi_tilehoriz")
i2=IupItem("Tile Vertical", "mdi_tilevert")
i3=IupItem("Cascade", "mdi_cascade")
i4=IupItem("Icon Arrange", "mdi_icon")
i5=IupItem("Close All", "mdi_closeall")
i6=IupSeparator()
i7=IupItem("Next", "mdi_next")
i8=IupItem("Previous", "mdi_previous")
winmenu = IupMenu(i1,i2,i3,i4,i5,i6,i7,i8,NULL)
submenu2 =IupSubmenu("Window", winmenu)
'main menu
mnu = IupMenu(submenu1, submenu2, null)
IupSetHandle("mnu",mnu)
IupSetHandle("mdiMenu",winmenu)
'callbacks, old depricated style
IupSetFunction("mdi_new", @mdi_new)
IupSetFunction("mdi_tilehoriz", @mdi_tilehoriz)
IupSetFunction("mdi_tilevert", @mdi_tilevert)
IupSetFunction("mdi_cascade", @mdi_cascade)
IupSetFunction("mdi_icon", @mdi_icon)
IupSetFunction("mdi_next", @mdi_next)
IupSetFunction("mdi_previous", @mdi_previous)
IupSetFunction("mdi_closeall", @mdi_closeall)
end sub
function createFrame() as sys
sys dlg, cnv, box, btn
cnv = IupCanvas( NULL)
IupSetAttribute(cnv,"MDICLIENT","YES")
IupSetAttribute(cnv,"MDIMENU","mdiMenu")
IupSetAttribute(cnv,"BGCOLOR","128 255 0")
btn = IupButton("Test", NULL)
IupSetCallback(btn,"ACTION", @button_cb)
box = IupHbox(btn, NULL)
IupSetAttribute(box,"MARGIN","5x5")
vbox = IupVbox(box, cnv, NULL)
dlg = IupDialog(vbox)
IupSetAttribute(dlg,"TITLE","MDI Frame")
IupSetAttribute(dlg,"MDIFRAME","YES")
IupSetAttribute(dlg,"RASTERSIZE","800x600")
IupSetAttribute(dlg,"MENU","mnu")
IupSetHandle("mdiFrame", dlg)
return dlg
end function
sub MdiTest()
sys dlg
createMenu()
dlg = createFrame()
' IupSetAttribute(dlg, "PLACEMENT", "MAXIMIZED")
IupShow(dlg)
IupSetAttribute(dlg,"RASTERSIZE", NULL)
end sub
sub main()
IupOpen(0,0)
MdiTest()
IupMainLoop()
IupClose()
end sub
main()