home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprocs / vsetup.icn < prev    next >
Text File  |  2000-07-29  |  7KB  |  251 lines

  1. ############################################################################
  2. #
  3. #    File:     vsetup.icn
  4. #
  5. #    Subject:  Procedures for vidget application setup
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     October 9, 1997
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  vsetup(win, cbk, wlist[]) initializes a set of widgets according to
  18. #  a list of specifications created by the interface editor VIB.
  19. #
  20. #  win can be an existing window, a list of command arguments to be
  21. #  passed to Window(), null, or omitted.  In the latter three cases
  22. #  a new window is opened if &window is null.
  23. #
  24. #  cbk is a default callback routine to be used when no callback is
  25. #  specified for a particular vidget.
  26. #
  27. #  wlist is a list of specifications; the first must be the Sizer and
  28. #  the last may be null.  Each specification is itself a list consisting
  29. #  of a specification string, a callback routine, and an optional list
  30. #  of additional specifications.  Specification strings vary by vidget
  31. #  type, but the general form is "ID:type:style:n:x,y,w,h:label".
  32. #
  33. #  vsetup returns a table of vidgets indexed by vidget ID.
  34. #  The root vidget is included with the ID of "root".
  35. #
  36. ############################################################################
  37. #
  38. #  Links:  graphics,
  39. #          vidgets, vslider, vmenu, vscroll, vtext, vbuttons, vradio, vlist
  40. #
  41. ############################################################################
  42.  
  43. link graphics
  44. link vidgets
  45. link vslider
  46. link vmenu
  47. link vscroll
  48. link vtext
  49. link vbuttons
  50. link vradio
  51. link vlist
  52.  
  53. record VS_rec(var, typ, sty, num, x, y, w, h, lbl, cbk, etc)
  54.  
  55.  
  56. ## vsetup(win, cbk, wlist[]) -- set up vidgets and return table of handles
  57. #
  58. #  win is an existing window, or a list of command args for Window(), or &null.
  59. #  cbk is a callback routine to use when a vidget's callback is null.
  60. #  wlist is a list of vidget specs as constructed by vib (or uix).
  61.  
  62. procedure vsetup(args[])
  63.    local r, wlbl, root, vtable, wspec, alist, win, winargs, cbk
  64.    static type
  65.  
  66.    initial type := proc("type", 0)    # protect attractive name
  67.  
  68.    case type(args[1]) of {        # check for window or arglist argument
  69.       "window":    win := get(args)
  70.       "list":    winargs := get(args)
  71.       "null":    get(args)
  72.       }
  73.    /win := &window
  74.  
  75.    if type(args[1]) ~== "list" then    # check for callback argument
  76.       cbk := get(args)
  77.  
  78.    wspec := get(args)            # first spec gives window size
  79.  
  80.    if /win then {            # if we don't have a window
  81.       r := VS_crack(wspec) | _Vbomb("bad specification in vsetup")
  82.       wlbl := ("" ~== r.lbl) |
  83.          (&progname ? {while tab(upto('/')+1); tab(upto('.')|0)})
  84.       alist := []
  85.       put(alist, "width=" || (r.x + r.w))
  86.       put(alist, "height=" || (r.y + r.h))
  87.       put(alist, "label=" || wlbl)
  88.       put(alist, \winargs)
  89.       win := Window ! alist
  90.       }
  91.  
  92.    VSetFont(win)            # set correct text font
  93.  
  94.    vtable := table()            # make table of handles
  95.    vtable["root"] := root := Vroot_frame(win)    # insert root frame
  96.    every r := VS_crack(\!args, cbk) do
  97.       vtable[r.var] := VS_obj(win, root, r)    # insert other vidgets
  98.    VResize(root)            # configure and realize vidgets
  99.    root.id := "root"
  100.    return vtable            # return table
  101. end
  102.  
  103.  
  104.  
  105. ## VS_crack(wspec, cbk) -- extract elements of spec and put into record
  106. #
  107. #  cbk is a default callback to use if the spec doesn't supply one.
  108.  
  109. procedure VS_crack(wspec, cbk)
  110.    local r, f
  111.  
  112.    r := VS_rec()
  113.    (get(wspec) | fail) ? { 
  114.       r.var := tab(upto(':')) | fail;  move(1)
  115.       r.typ := tab(upto(':')) | fail;  move(1)
  116.       r.sty := tab(upto(':')) | fail;  move(1)
  117.       r.num := tab(upto(':')) | fail;  move(1)
  118.       r.x := tab(upto(',')) | fail;  move(1)
  119.       r.y := tab(upto(',')) | fail;  move(1)
  120.       r.w := tab(upto(',')) | fail;  move(1)
  121.       r.h := tab(upto(':')) | fail;  move(1)
  122.       r.lbl := tab(0)
  123.       }
  124.    r.cbk := \get(wspec) | cbk
  125.    r.etc := get(wspec)
  126.    return r
  127. end
  128.  
  129.  
  130.  
  131. ## VS_obj(win, root, r) -- create vidget depending on type
  132.  
  133. procedure VS_obj(win, root, r)
  134.    local obj, gc, p, lo, hi, iv, args
  135.    static image
  136.  
  137.    initial image := proc("image", 0)
  138.  
  139.    case r.typ of {
  140.       "Label" | "Message": {
  141.          obj := Vmessage(win, r.lbl)
  142.          VInsert(root, obj, r.x, r.y, r.w, r.h)
  143.          obj.id := r.var
  144.          }
  145.       "Line": {
  146.          obj := Vline(win, r.x, r.y, r.w, r.h)
  147.          obj.id := r.var
  148.          VInsert(root, obj)
  149.          }
  150.       "Rect": {
  151.          if r.sty == "" then
  152.             if integer(r.num) > 0 then
  153.                r.sty := "grooved"
  154.             else
  155.                r.sty := "invisible"
  156.          obj := Vpane(win, r.cbk, r.var, r.sty)
  157.          VInsert(root, obj, r.x, r.y, r.w, r.h)
  158.          }
  159.       "Check": {
  160.          obj := Vcheckbox(win, r.cbk, r.var, r.w)
  161.          VInsert(root, obj, r.x, r.y, r.w, r.h)
  162.          }
  163.       "Button": {
  164.          if r.num == "1" then
  165.             p := Vtoggle
  166.          else
  167.             p := Vbutton
  168.          obj := p(win, r.lbl, r.cbk, r.var, r.sty, r.w, r.h)
  169.          VInsert(root, obj, r.x, r.y)
  170.          }
  171.       "Choice": {
  172.          obj := Vradio_buttons(win, r.etc, r.cbk, r.var, V_DIAMOND_NO)
  173.          VInsert(root, obj, r.x, r.y)
  174.          }
  175.       "Slider" | "Scrollbar" : {
  176.          r.lbl ? {
  177.             lo := numeric(tab(upto(',')))
  178.             move(1)
  179.             hi := numeric(tab(upto(',')))
  180.             move(1)
  181.             iv := numeric(tab(0))
  182.             }
  183.          if r.num == "" then
  184.             r.num := &null
  185.          obj := case (r.sty || r.typ) of {
  186.             "hSlider":
  187.                Vhoriz_slider(win, r.cbk, r.var, r.w, r.h, lo, hi, iv, r.num)
  188.             "vSlider":
  189.                Vvert_slider(win, r.cbk, r.var, r.h, r.w, hi, lo, iv, r.num)
  190.             "hScrollbar":
  191.                Vhoriz_scrollbar(win, r.cbk, r.var, r.w, r.h, lo, hi, , , r.num) 
  192.             "vScrollbar":
  193.                Vvert_scrollbar(win, r.cbk, r.var, r.h, r.w, hi, lo, , , r.num)
  194.             }
  195.          VSetState(obj, iv)            # needed for scrollbars
  196.          VInsert(root, obj, r.x, r.y)
  197.          }
  198.       "Text": {
  199.          obj := Vtext(win, r.lbl, r.cbk, r.var, r.num)
  200.          VInsert(root, obj, r.x, r.y)
  201.          }
  202.       "Menu": {
  203.          obj := Vmenu_bar(win, r.lbl, VS_submenu(win, r.etc, r.cbk))
  204.          obj.id := obj.lookup[1].id := r.var
  205.          VInsert(root, obj, r.x, r.y)
  206.          }
  207.       "List": {
  208.          if integer(r.num) > 0 then
  209.             r.num := 1
  210.          else
  211.             r.num := &null
  212.          obj := Vlist(win, r.cbk, r.var, [], r.num, r.w, r.h, r.sty)
  213.          VInsert(root, obj, r.x, r.y)
  214.          }
  215.       "List": {
  216.          if integer(r.num) > 0 then
  217.             r.num := 1
  218.          else
  219.             r.num := &null
  220.          obj := Vlist(win, r.cbk, r.var, [], r.num, r.w, r.h, r.sty)
  221.          VInsert(root, obj, r.x, r.y)
  222.          }
  223.       default: {
  224.          _Vbomb("unrecognized object in vsetup: " || image(r.typ))
  225.          fail
  226.          }
  227.    }
  228.    return obj
  229. end
  230.  
  231.  
  232.  
  233. ## VS_submenu(win, lst, cbk) -- create submenu vidget
  234.  
  235. procedure VS_submenu(win, lst, cbk)
  236.    local a, c, lbl
  237.    static type
  238.  
  239.    initial type := proc("type", 0)    # protect attractive name
  240.  
  241.    a := [win]
  242.    while *lst > 0 do {
  243.       put(a, get(lst))
  244.       if type(lst[1]) == "list" then
  245.          put(a, VS_submenu(win, get(lst), cbk))
  246.       else
  247.          put(a, cbk)
  248.       }
  249.    return Vsub_menu ! a
  250. end
  251.