home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / ButtonBar_v10.lha / ButtonBar.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1994-01-12  |  5.6 KB  |  178 lines

  1. /* $VER: ButtonBar v1.00 (12.01.94)
  2.  *
  3.  * This little ditty will generate a button bar on a public screen with
  4.  * whatever commands are sent to it.
  5.  *
  6.  * See the Documentation for a better description
  7.  *
  8.  * Problems that still need help:
  9.  *   Buttons only really look good on screens that use 8 pt fonts, needs
  10.  *     to work for other size windows (via Mike Groshart's PubScreenFont
  11.  *     program hopefully)
  12.  *
  13.  * Requires the following libraries:
  14.  *   rexxsupport.library
  15.  *   rexxarplib.library
  16.  */
  17.  
  18. template_dir = "s:"
  19.  
  20. signal on error
  21. signal on halt
  22. signal on failure
  23. options results
  24.  
  25. /* load in rexxarplib.library if it already isn't and it exists */
  26. if ~show(l,'rexxarplib.library') then do
  27.   if ~addlib("rexxarplib.library",0,-30,0) then do
  28.     say "Can't open rexxarplib.library"
  29.     exit
  30.   end
  31. end
  32.  
  33. /* load in rexxsupport.library if it already isn't and it exists */
  34. if ~show(l,'rexxsupport.library') then do
  35.   if ~addlib("rexxsupport.library",0,-30,0) then do
  36.     say "Can't open rexxsupport.library"
  37.     exit
  38.   end
  39. end
  40.  
  41. parse arg tfile_name.1
  42.  
  43. if tfile_name.1 = ""  /* did a config file come in from the command line ? */
  44.   then result = GetFile(10,10,template_dir,"terminus.template","Pick a File",,"PATGAD",tfile_name,,,"#?.template")
  45.  
  46. if result = 0 then exit /* didn't pick any files; get the heck out of here! */
  47.  
  48. call get_data(tfile_name.1)  /* go read in the info from the template file */
  49.  
  50. /* now we have the font size and number of buttons, create the window and
  51.  * fill it in with buttons.
  52.  */
  53.  
  54. bbar.buttonsize = 12 /* max # of characters to go in a button */
  55. bbar.charwidth  = 9
  56.  
  57. /* create the port and check to see if it get's created okay */
  58.  
  59. address AREXX "'call CreateHost(BBARHOST,BBARPORT,"bbar.screen_name")'"
  60.  
  61. do for 50 while ~show('P','BBARHOST')
  62.   call delay(10)
  63. end
  64.  
  65. if ~show('P','BBARHOST') then do /* see if the public screen actually exists */
  66.   result = Request(10,10,"Can't find the public screen: "bbar.screen_name," Exit "," Exit ")
  67.   exit
  68. end
  69.  
  70. idcmp     = 'CLOSEWINDOW+GADGETUP'
  71. flags     = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+BACKFILL'
  72. WinHeight = 16 + bbar.rows * (bbar.fontsize+7)
  73. WinWidth  = bbar.cols * (bbar.buttonsize * bbar.charwidth) + 8
  74.  
  75. /* check to see if the # of rows and columns will fit on this screen */
  76.  
  77. MaxRows = ScreenRows(bbar.screen_name)      /* get max # of rows on the screen */
  78. if MaxRows = -1 then MaxRows = ScreenRows() /* try again using workbench screen */
  79.  
  80. MaxCols = ScreenCols(bbar.screen_name)      /* get max # of columns on the screen */
  81. if MaxCols = -1 then MaxCols = ScreenCols() /* try again using workbench screen */
  82.  
  83. if (MaxCols ~= -1) & (WinWidth + bbar.y >= MaxCols) then do
  84.   result = Request(10,10,"Too many rows defined for screen, please change\the rows and/or columns", ," Exit ")
  85.   exit
  86. end
  87.  
  88. if (MaxRows ~= -1) & (WinHeight + bbar.x >= MaxRows) then do
  89.   result = Request(10,10,"Too many columns defined for screen, please change\the rows and/or columns", ," Exit ")
  90.   exit
  91. end
  92.  
  93. call OpenWindow(BBARHOST, bbar.x, bbar.y, WinWidth, WinHeight, idcmp, flags, "Button Bar ["bbar.screen_name"]")
  94. call SetFont(BBARHOST, bbar.fontname, bbar.fontsize)
  95.  
  96. /* now start filling in the window with buttons */
  97.  
  98. do i = 1 to bbar.rows
  99.   do j = 1 to bbar.cols
  100.     row = 6 + bbar.buttonsize * bbar.charwidth * (j-1)  /* space-over-from-left-edge + (maxsize * font width * current-column */
  101.     col = (bbar.fontsize * 2 - 1) * i
  102.     index = ((i-1) * bbar.cols) + j
  103.     if index <= bbar.cnt then call AddGadget('BBARHOST', row, col, index, bbar.button.index, bbar.action.index)
  104.   end
  105. end
  106.  
  107. address value bbar.screen_name  /* address this newly created window */
  108.  
  109. quitflag = 0
  110.  
  111. call openport(BBARPORT)         /* open the port to the window */
  112.  
  113. top:
  114.  
  115. do until quitflag = 1           /* keep going until told to quit               */
  116.   call waitpkt(BBARPORT)        /* wait for something to happen in the window  */
  117.   packet = getpkt(BBARPORT)     /* Got something! What was it?                 */
  118.   if packet ~= null() then do
  119.     cmd = getarg(packet)        /* find out what the command was in the packet */
  120.     if cmd = CLOSEWINDOW then quitflag = 1  /* time to quit ButtonBar? */
  121.     else do
  122.       if ~showlist('p',bbar.screen_name) then do /* see if the public screen actually exists */
  123.         result = Request(10,10,"Can't find the public screen: "bbar.screen_name, ," Exit ")
  124.         signal exit_point
  125.       end
  126.       cmd                       /* do the command. This is the line we've been working towards? :) */
  127.     end
  128.     call reply(packet,0)        /* go ahead and check for more */
  129.   end
  130. end
  131.  
  132. signal exit_point
  133.  
  134. failure:
  135.  
  136. result = Request(10,10,"Error executing command:" cmd, ," Keep Going "," Exit ButtonBar ",bbar.screen_name)
  137. if result = "OKAY" then signal top
  138.  
  139. halt:
  140. error:
  141. exit_point:
  142.  
  143. call CloseWindow(BBARHOST)
  144. call ClosePort(BBARPORT)
  145.  
  146. exit
  147.  
  148. get_data: procedure expose bbar.
  149.   /* read in the file based on the name passed, leave the info the
  150.    * stem variable named "bbar."
  151.    */
  152.   parse arg template_file
  153.  
  154.   call open(tfile,template_file,'r') /* go open the button template file */
  155.  
  156.   bbar.screen_name = readln(tfile)
  157.   parse value readln(tfile) with bbar.rows "," bbar.cols
  158.   parse value readln(tfile) with bbar.fontname "," bbar.fontsize
  159.   parse value readln(tfile) with bbar.x "," bbar.y
  160.  
  161.   if upper(right(bbar.fontname,5)) ~= ".FONT" then bbar.fontname = bbar.fontname".font"
  162.  
  163.   maxcnt = bbar.rows * bbar.cols
  164.   bbar.cnt = 0
  165.  
  166.   do i = 1 to maxcnt while ~eof(tfile)
  167.     parse value readln(tfile) with bbar.button.i "," bbar.action.i
  168.     /* force buttons to be exactly 12 characters, centering
  169.      * (or trimming) if necessary
  170.      */
  171.     bbar.cnt = bbar.cnt + 1
  172.     bbar.button.i = center(bbar.button.i,12)
  173.  
  174.   end
  175.   call close(tfile)
  176.  
  177.   return
  178.