home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 504a.lha / hypertext / Rexx / setup.dme < prev    next >
Text File  |  1991-05-01  |  6KB  |  274 lines

  1. /*   This program will let a user specify various setup options for an HT
  2.  * document from within their text editor.
  3.  */
  4. /****************
  5.  * D.B.G. 1990
  6.  ****************/
  7.  
  8.  /* should check for failure of these calls */
  9.  if ~Show('L', 'rexxsupport.library') then
  10.   check = AddLib('rexxsupport.library', 10, -30, 0)
  11.  if (check == 0) then do
  12.      say "Need to have the rexxsupport library in LIBS:!"
  13.      exit
  14.    end
  15.  
  16.  
  17.  if ~Show('L', 'rexxarplib.library') then
  18.   check = AddLib('rexxarplib.library', 10, -30, 0)
  19.  if (check == 0) then do
  20.    say "Need to have the rexxarplib.library and screenshare.library in LIBS:"
  21.    exit
  22.   end
  23.  
  24.  
  25.  /* this variable and its stems define the gadget names and the
  26.   * associated file name.  Change them to suit your system.
  27.   */
  28.  cport = 'SETUP_PORT'
  29.  notport = 'SETUP_notify'
  30.  
  31.  address AREXX "'x=call CreateHost(" cport "," notport ")'"
  32.  
  33.  do until ShowList(P,cport)
  34.    call Delay(10)
  35.   end
  36.  
  37.  idcmp = 'CLOSEWINDOW+WINDOWDRAG+GADGETUP'
  38.  flags = 'WINDOWCLOSE+WINDOWDRAG+BACKFILL'
  39.  call OpenWindow(cport, 100, 20, 450, 130, idcmp, flags, 'Setup Requestor')
  40.  call ActivateWindow(cport)
  41.  
  42.  call SetDrMd(cport, COMPLEMENT)
  43.  call Move(cport, 20, 20)
  44.  call Text(cport, "Help Filename : ")
  45.  call AddGadget(cport, 155,  14,  "Help", "", "help = '%g'", 250)
  46.  
  47.  call Move(cport, 20, 40)
  48.  call Text(cport, "Window Title : ")
  49.  call AddGadget(cport, 155,  34,  "Title", "", "title = '%g'", 250)
  50.  
  51.  call Move(cport, 20, 60)
  52.  call Text(cport, "Font Name : ")
  53.  call AddGadget(cport, 115,  54,  "Font", "", "font = '%g'", 130)
  54.  
  55.  call Move(cport, 295, 60)
  56.  call Text(cport, "Size : ")
  57.  call AddGadget(cport, 355, 54,  "Size", "", "size = '%g'", 50)
  58.  
  59.  call Move(cport, 35, 70)
  60.  call Draw(cport, 390, 70)
  61.  
  62.  
  63.  /* FIXME : the following code is very brain dead and should be in some
  64.   *        sort of a loop or function call.
  65.   */
  66.  
  67.  /* do the foreground color gadgets */
  68.  call Move(cport, 20, 80)
  69.  call Text(cport, "Foreground Color")
  70.  
  71.  call SetDrMd(cport, JAM1)
  72.  call AddGadget(cport, 20, 85, "fgcolor0", "  ", "fg = 0 ; call highlight_type 20 85")
  73.  call SetAPen(cport, 0)
  74.  call RectFill(cport, 22, 86, 38, 93)
  75.  
  76.  call AddGadget(cport, 50, 85, "fgcolor1", "  ", "fg = 1 ; call highlight_type 50 85")
  77.  call SetAPen(cport, 1)
  78.  call RectFill(cport, 52, 86, 68, 93)
  79.  
  80.  call AddGadget(cport, 80, 85, "fgcolor2", "  ", "fg = 2 ; call highlight_type 80 85")
  81.  call SetAPen(cport, 2)
  82.  call RectFill(cport, 82, 86, 98, 93)
  83.  
  84.  call AddGadget(cport, 110, 85, "fgcolor3", "  ", "fg = 3 ; call highlight_type 110 85")
  85.  call SetAPen(cport, 3)
  86.  call RectFill(cport, 112, 86, 128, 93)
  87.  
  88.  
  89.  /* now do the background colors */
  90.  call Move(cport, 280, 80)
  91.  call Text(cport, "Background Color")
  92.  
  93.  call SetDrMd(cport, JAM1)
  94.  call AddGadget(cport, 290, 85, "bgcolor0", "  ", "bg = 0 ; call highlight_type 290 85")
  95.  call SetAPen(cport, 0)
  96.  call RectFill(cport, 292, 86, 308, 93)
  97.  
  98.  call AddGadget(cport, 320, 85, "bgcolor1", "  ", "bg = 1 ; call highlight_type 320 85")
  99.  call SetAPen(cport, 1)
  100.  call RectFill(cport, 322, 86, 338, 93)
  101.  
  102.  call AddGadget(cport, 350, 85, "bgcolor2", "  ", "bg = 2 ; call highlight_type 350 85")
  103.  call SetAPen(cport, 2)
  104.  call RectFill(cport, 352, 86, 368, 93)
  105.  
  106.  call AddGadget(cport, 380, 85, "bgcolor3", "  ", "bg = 3 ; call highlight_type 380 85")
  107.  call SetAPen(cport, 3)
  108.  call RectFill(cport, 382, 86, 398, 93)
  109.  
  110.  /* o.k. and cancel gadgets */
  111.  call AddGadget(cport, 20, 110, "ok", "  O.K.  ", "ok")
  112.  call AddGadget(cport, 340, 110, "cancel", " Cancel ", "cancel")
  113.  
  114.  mainport = 'SP'
  115.  mport = OpenPort(mainport)
  116.  do until ShowList(P, mainport)
  117.    call delay(10)
  118.   end
  119.  
  120.  call SetNotify(cport, GADGETUP, mainport)
  121.  call SetNotify(cport, CLOSEWINDOW, mainport)
  122.  
  123.  notquit = 1
  124.  
  125.  /* main event loop */
  126.  do while notquit
  127.     call WaitPkt(mainport)
  128.     packet = GetPkt(mainport)
  129.  
  130.     if packet ~== '0000 0000'x then
  131.      do
  132.       id = GetArg(packet, 0)
  133.       call Reply(packet, 0)
  134.  
  135.       if (word(id, 1) = "fg" | word(id, 1) = "bg") then do
  136.      if (word(id, 1) = "bg") then
  137.        i = 290
  138.      else
  139.        i = 20
  140.      call SetAPen(cport, 1)
  141.      call RectFill(cport, i, 98, i+150, 105)
  142.      call SetAPen(cport, 3)
  143.        end
  144.  
  145.       select
  146.     when id = 'CLOSEWINDOW' then call closeup()
  147.     when id = 'cancel'      then call closeup()
  148.     when id = 'ok'          then call goodbye()
  149.     otherwise interpret id
  150.       end
  151.      end
  152.  end
  153. exit
  154.  
  155.  
  156. /* this function will exit cleanly from this program */
  157. closeup:
  158.  call stop("SETUP_PORT")
  159.  
  160.  exit
  161. return
  162.  
  163.  
  164. /* this should insert the appropriate text */
  165. goodbye:
  166.  
  167.  'ping 9'                 /* set current position */
  168.  'top'                    /* move to beginning of buffer */
  169.  'first'
  170.  
  171.  help = ""
  172.  string = get_gadg_string("HELP")
  173.  interpret string
  174.  if help ~= "" then do
  175.    'insline'
  176.    '('"\\\help " help')'
  177.    'first'
  178.   end
  179.  
  180.  title = ""
  181.  string = get_gadg_string("TITLE")
  182.  interpret string
  183.  if title ~= "" then do
  184.    'insline'
  185.    '('"\\\title "title ')'
  186.    'first'
  187.   end
  188.  
  189.  font = ""
  190.  string = get_gadg_string("FONT")
  191.  interpret string
  192.  
  193.  size = ""
  194.  string = get_gadg_string("SIZE")
  195.  interpret string
  196.  
  197.  if font ~= "" & size ~= "" & datatype(size, NUM) then do
  198.    'insline'
  199.    '('"\\\font" font size ')'
  200.    'first'
  201.   end
  202.  
  203.  if fg ~= "FG" then do
  204.    'insline'
  205.    '('"\\\fgcolor "fg ')'
  206.    'first'
  207.   end
  208.  
  209.  if bg ~= "BG" then do
  210.    'insline'
  211.    '('"\\\bgcolor "bg ')'
  212.    'first'
  213.   end
  214.  
  215.  'pong 9'
  216.  call closeup()
  217. return
  218.  
  219.  
  220.  
  221. /* this function puts a little triangle beneath a boolean gadget to indicate
  222.  * that it is highlighted.
  223.  */
  224. highlight_type:
  225.  arg x y
  226.  
  227.  y = y - 1
  228.  call AreaMove(cport, x+5, y+20)
  229.  call AreaDraw(cport, x+15, y+20)
  230.  call AreaDraw(cport, x+10, y+15)
  231.  call AreaDraw(cport, x+5, y+20)
  232.  call AreaEnd(cport)
  233.  
  234.  drop x y
  235. return
  236.  
  237. do_filerequest:
  238.   res = GetFile(15, 10, "", "", "Select name of file use:")
  239.   cur_name = get_gadg_string()
  240.  
  241.   /* if true, we have to extract relevant info and keep it */
  242.   if cur_name ~= "" then do
  243.       parse var cur_name . stuff
  244.       res = res || stuff
  245.     end
  246.  
  247.   gadg.9.name = res
  248.  
  249.   call RemoveGadget(cport, "gadg9")
  250.   call AddGadget(cport, 25,  105, "gadg9", gadg.9.name,  "%g", 250)
  251.   call RefreshGadgets(cport)
  252.   call ActivateGadget(cport, "gadg9")
  253.  
  254.   drop res cur_name
  255. return
  256.  
  257.  
  258. /* returns the string contained in the string gadget.  This routine
  259.  * should be generalized more
  260.  */
  261. get_gadg_string:
  262.  arg gadget_name
  263.  
  264.  options results
  265.  call ReadGadget(cport, gadget_name)
  266.  call WaitPkt(mainport)
  267.  packet = GetPkt(mainport)
  268.  ret = GetArg(packet, 0)
  269.  call Reply(packet, 0)
  270.  
  271. return ret
  272.  
  273.  
  274.