home *** CD-ROM | disk | FTP | other *** search
- /* $VER: ButtonBar v1.00 (12.01.94)
- *
- * This little ditty will generate a button bar on a public screen with
- * whatever commands are sent to it.
- *
- * See the Documentation for a better description
- *
- * Problems that still need help:
- * Buttons only really look good on screens that use 8 pt fonts, needs
- * to work for other size windows (via Mike Groshart's PubScreenFont
- * program hopefully)
- *
- * Requires the following libraries:
- * rexxsupport.library
- * rexxarplib.library
- */
-
- template_dir = "s:"
-
- signal on error
- signal on halt
- signal on failure
- options results
-
- /* load in rexxarplib.library if it already isn't and it exists */
- if ~show(l,'rexxarplib.library') then do
- if ~addlib("rexxarplib.library",0,-30,0) then do
- say "Can't open rexxarplib.library"
- exit
- end
- end
-
- /* load in rexxsupport.library if it already isn't and it exists */
- if ~show(l,'rexxsupport.library') then do
- if ~addlib("rexxsupport.library",0,-30,0) then do
- say "Can't open rexxsupport.library"
- exit
- end
- end
-
- parse arg tfile_name.1
-
- if tfile_name.1 = "" /* did a config file come in from the command line ? */
- then result = GetFile(10,10,template_dir,"terminus.template","Pick a File",,"PATGAD",tfile_name,,,"#?.template")
-
- if result = 0 then exit /* didn't pick any files; get the heck out of here! */
-
- call get_data(tfile_name.1) /* go read in the info from the template file */
-
- /* now we have the font size and number of buttons, create the window and
- * fill it in with buttons.
- */
-
- bbar.buttonsize = 12 /* max # of characters to go in a button */
- bbar.charwidth = 9
-
- /* create the port and check to see if it get's created okay */
-
- address AREXX "'call CreateHost(BBARHOST,BBARPORT,"bbar.screen_name")'"
-
- do for 50 while ~show('P','BBARHOST')
- call delay(10)
- end
-
- if ~show('P','BBARHOST') then do /* see if the public screen actually exists */
- result = Request(10,10,"Can't find the public screen: "bbar.screen_name," Exit "," Exit ")
- exit
- end
-
- idcmp = 'CLOSEWINDOW+GADGETUP'
- flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+BACKFILL'
- WinHeight = 16 + bbar.rows * (bbar.fontsize+7)
- WinWidth = bbar.cols * (bbar.buttonsize * bbar.charwidth) + 8
-
- /* check to see if the # of rows and columns will fit on this screen */
-
- MaxRows = ScreenRows(bbar.screen_name) /* get max # of rows on the screen */
- if MaxRows = -1 then MaxRows = ScreenRows() /* try again using workbench screen */
-
- MaxCols = ScreenCols(bbar.screen_name) /* get max # of columns on the screen */
- if MaxCols = -1 then MaxCols = ScreenCols() /* try again using workbench screen */
-
- if (MaxCols ~= -1) & (WinWidth + bbar.y >= MaxCols) then do
- result = Request(10,10,"Too many rows defined for screen, please change\the rows and/or columns", ," Exit ")
- exit
- end
-
- if (MaxRows ~= -1) & (WinHeight + bbar.x >= MaxRows) then do
- result = Request(10,10,"Too many columns defined for screen, please change\the rows and/or columns", ," Exit ")
- exit
- end
-
- call OpenWindow(BBARHOST, bbar.x, bbar.y, WinWidth, WinHeight, idcmp, flags, "Button Bar ["bbar.screen_name"]")
- call SetFont(BBARHOST, bbar.fontname, bbar.fontsize)
-
- /* now start filling in the window with buttons */
-
- do i = 1 to bbar.rows
- do j = 1 to bbar.cols
- row = 6 + bbar.buttonsize * bbar.charwidth * (j-1) /* space-over-from-left-edge + (maxsize * font width * current-column */
- col = (bbar.fontsize * 2 - 1) * i
- index = ((i-1) * bbar.cols) + j
- if index <= bbar.cnt then call AddGadget('BBARHOST', row, col, index, bbar.button.index, bbar.action.index)
- end
- end
-
- address value bbar.screen_name /* address this newly created window */
-
- quitflag = 0
-
- call openport(BBARPORT) /* open the port to the window */
-
- top:
-
- do until quitflag = 1 /* keep going until told to quit */
- call waitpkt(BBARPORT) /* wait for something to happen in the window */
- packet = getpkt(BBARPORT) /* Got something! What was it? */
- if packet ~= null() then do
- cmd = getarg(packet) /* find out what the command was in the packet */
- if cmd = CLOSEWINDOW then quitflag = 1 /* time to quit ButtonBar? */
- else do
- if ~showlist('p',bbar.screen_name) then do /* see if the public screen actually exists */
- result = Request(10,10,"Can't find the public screen: "bbar.screen_name, ," Exit ")
- signal exit_point
- end
- cmd /* do the command. This is the line we've been working towards? :) */
- end
- call reply(packet,0) /* go ahead and check for more */
- end
- end
-
- signal exit_point
-
- failure:
-
- result = Request(10,10,"Error executing command:" cmd, ," Keep Going "," Exit ButtonBar ",bbar.screen_name)
- if result = "OKAY" then signal top
-
- halt:
- error:
- exit_point:
-
- call CloseWindow(BBARHOST)
- call ClosePort(BBARPORT)
-
- exit
-
- get_data: procedure expose bbar.
- /* read in the file based on the name passed, leave the info the
- * stem variable named "bbar."
- */
- parse arg template_file
-
- call open(tfile,template_file,'r') /* go open the button template file */
-
- bbar.screen_name = readln(tfile)
- parse value readln(tfile) with bbar.rows "," bbar.cols
- parse value readln(tfile) with bbar.fontname "," bbar.fontsize
- parse value readln(tfile) with bbar.x "," bbar.y
-
- if upper(right(bbar.fontname,5)) ~= ".FONT" then bbar.fontname = bbar.fontname".font"
-
- maxcnt = bbar.rows * bbar.cols
- bbar.cnt = 0
-
- do i = 1 to maxcnt while ~eof(tfile)
- parse value readln(tfile) with bbar.button.i "," bbar.action.i
- /* force buttons to be exactly 12 characters, centering
- * (or trimming) if necessary
- */
- bbar.cnt = bbar.cnt + 1
- bbar.button.i = center(bbar.button.i,12)
-
- end
- call close(tfile)
-
- return
-