Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- . the menu window definition
- windef init "WINDOW=MENUWIN, TITLE=Menu, SIZE=440:270, FIXSIZE"
- . the menu panel resource definition
- menudef init "PANEL=MENUPAN,SIZE=440:375":
- ",H=14,V=15,LISTBOX=10:200:250,INSERTORDER":
- ",H=228,LISTBOX=20:200:250,INSERTORDER"
- . The menu file
- menufile file var=81, text
- mnfilename init "menudemo"
- . the menu record (records in the menu file)
- menu record
- rtype char 1 . record type: 1 (main menu), 2 (submenu), X (chain pgm)
- text char 80 . text or program name
- recordend
- . the GUI objects
- windev device
- winpan resource
- mainq queue entries=100, size=100
- . the main queue message
- msg record
- name char 8
- func char 4
- item char 5
- data char 83
- recordend
- . various work variables
- programs char @[,]
- progname char 60
- work char 65000
- type1count int 3
- type2count int 3
- type2text char @[,]
- zero int "0"
- seq int "-2"
- . prepare and show the menu window, linking messages to the main queue
- prep windev, windef
- change windev, "statusbar"; " "
- link windev, mainq
- prep winpan, menudef
- change winpan, "itemon"
- change winpan, "lineon"
- change winpan, "focuson"
- link winpan, mainq
- show winpan, windev
- . show the user name and password dialog, then read and show menu items
- call showdialog
- call initmenu
- . receive and process messages
- loop
- wait mainq
- get mainq; msg
- display msg
- switch msg.name
- case "MENUWIN "
- call menuwindow
- case "MENUPAN "
- call menupanel
- endswitch
- repeat
- . process a message from the menu window device
- menuwindow
- switch msg.func
- case "CLOS"
- stop
- endswitch
- return
- . process a message from the menu panel resource
- menupanel
- switch msg.func
- case "PICK"
- call menupick
- case "ITEM"
- call menuitem
- case "FOCS"
- call menufocus
- case "FOCL"
- call menufocus
- case "NKEY"
- call menukeypress
- endswitch
- return
- . process a PICK message from the menu panel resource
- menupick lroutine
- i1 num 5
- i2 num 5
- err char 60
- if (msg.item = " 20")
- query winpan, "status10"; i1
- query winpan, "status20"; i2
- trap menupickfail giving err if cfail
- move programs[i1, i2] to progname
- chain progname
- endif
- return
- menupickfail
- change windev, "statusbar"; ("CHAIN FAILURE: " + progname + " " + err)
- noreturn
- return
- endroutine
- . process an ITEM message from the menu panel resource
- menuitem
- change windev, "statusbar"; " "
- if (msg.item = " 10")
- call leftlistselectionchanged
- endif
- return
- . process a FOCS message from the menu panel resource
- menufocus
- if (msg.item = " 20")
- if (msg.func = "FOCS")
- change winpan, "selectline20"; "1"
- else
- change winpan, "deselectline20"
- endif
- endif
- return
- .
- . routine to handle key press
- .
- menukeypress lroutine
- if ((int (squeeze msg.data)) = 256)
- if (msg.item = " 10")
- change winpan, "FOCUS20"
- else if (msg.item = " 20")
- call menupick
- endif
- endif
- return
- endroutine
- .
- . routine to handle a change in the highlighted left side menu
- .
- leftlistselectionchanged lroutine
- i1 int 5
- i2 num 5
- query winpan, "status10"; i2
- clear work
- for i1 from 1 to type2count
- break if (size type2text[i2, i1] < 1)
- if (i1 != 1)
- append ",", work
- endif
- append type2text[i2, i1], work
- repeat
- change winpan, "erase20"
- reset work
- change winpan, "minsert20"; *ll, work
- return
- endroutine
- .
- . routine to read the menu file and initialize the lists
- .
- initmenu lroutine
- i1 int 3
- i2 int 4
- twocount int 3
- twosize int " -1"
- execsize int " -1"
- open menufile, mnfilename
- . count the type 1 records, find the maximum type 2 record count per type 1 record
- reposit menufile, zero
- loop
- read menufile, seq; menu
- break if over
- move (length (chop menu.text)) to i1
- if (menu.rtype = "1")
- add 1 to type1count
- if (twocount > type2count)
- move twocount to type2count
- endif
- clear twocount
- else if (menu.rtype = "2")
- if (i1 > twosize)
- move i1 to twosize
- endif
- add 1 to twocount
- else if (menu.rtype = "X" or menu.rtype = "x")
- if (i1 > execsize)
- move i1 to execsize
- endif
- endif
- repeat
- if (twocount > type2count)
- move twocount to type2count
- endif
- . make an array to hold the text of the type 2 records
- return if (type2count < 1)
- clear work
- append "C", work
- append twosize, work
- append "[", work
- append type1count, work
- append ",", work
- append type2count, work
- append "]", work
- reset work
- makevar work, type2text
- . make an array to hold the names of the programs
- clear work
- append "C", work
- append execsize, work
- append "[", work
- append type1count, work
- append ",", work
- append type2count, work
- append "]", work
- reset work
- makevar work, programs
- . read the file again, capture the text of the type 2 and X records,
- . and insert the text of the type 1 records into the left list.
- reposit menufile, zero
- clear i1, i2, work
- loop
- read menufile, seq; menu
- break if over
- if (menu.rtype = "1")
- add 1 to i1
- chop menu.text to menu.text
- if (i1 != 1)
- append ",", work
- endif
- append menu.text, work
- clear i2
- else if (menu.rtype = "2")
- add 1 to i2
- chop menu.text to type2text[i1, i2]
- else if (menu.rtype = "X" or menu.rtype = "x")
- chop menu.text to programs[i1, i2]
- endif
- repeat
- close menufile
- reset work
- change winpan, "minsert10"; *ll, work
- . select the first line in the left list and populate the right list
- change winpan, "locateline10"; "1"
- call leftlistselectionchanged
- return
- endroutine
- .
- . routine to show a dialog to ask for user name and password
- . for this demo, we only look for 'pass' in the password edit box
- .
- showdialog lroutine
- logindef init "DIALOG=LOGINDLG,SIZE=290:150, TITLE=Login":
- ",H=60,V=17,TEXT=Enter user name and password":
- ",H=49,V=48,TEXT=User name\:":
- ",H=145,EDIT=10::80":
- ",H=49,V=75,TEXT=Password\:":
- ",H=145,PEDIT=20::80":
- ",H=49,V=110,DEFPUSHBUTTON=10000:Login:80:24":
- ",H=161,ESCPUSHBUTTON=20000:Cancel:80:24"
- logdlg resource
- logdlgq queue size=50
- user char 30
- pswd char 30
- prep logdlg, logindef
- link logdlg, logdlgq
- show logdlg, windev
- . get messages from the dialog queue
- loop
- wait logdlgq
- get logdlgq; msg
- stop if (msg.func = "CLOS")
- stop if (msg.item = "20000" and msg.func = "PUSH")
- break if (msg.item = "10000" and msg.func = "PUSH")
- repeat
- hide logdlg
- unlink logdlg
- query logdlg, "STATUS10"; user
- query logdlg, "STATUS20"; pswd
- stop if (trim(pswd) != "pass")
- close logdlg
- return
- endroutine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement