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 / gpacks / vib / vibradio.icn < prev    next >
Text File  |  2000-07-29  |  7KB  |  210 lines

  1. ############################################################################
  2. #
  3. #  vibradio.icn -- procedures for defining a radio button object
  4. #
  5. ############################################################################
  6. #
  7. #   This file is in the public domain.
  8. #
  9. ############################################################################
  10.  
  11. $include "vibdefn.icn"
  12.  
  13. global RB_starty, RADIO_TALK, RADIO_VIDGET
  14.  
  15. ##########################################################################
  16. # radio_button_obj:
  17. #    v       : vidget used for drawing radio button
  18. #    proc    : name of user callback procedure
  19. #    id      : unique means of identifying instance
  20. #    x,y,w,h : bounding box
  21. #    focus   : should focus lines be drawn around this object?
  22. #    alts    : a list of button labels making up the radio button object
  23. ##########################################################################
  24. record radio_button_obj(v, proc, id, x, y, w, h, focus, alts)
  25.  
  26. ##########################################################################
  27. # create_radio_button() creates a radio button instance and draws the
  28. #                       button if it is a first class object.
  29. ##########################################################################
  30. procedure create_radio_button(x, y, alts)
  31.    local r, id
  32.  
  33.    id := next_id("radio_button")
  34.    r := radio_button_obj(, "radio_button_cb" || id, "radio_button" || id,
  35.                           x, y, 0, 0, 0, alts)
  36.    r.v := Vradio_buttons(ROOT, x, y, APPWIN, alts, , id, V_DIAMOND_NO)
  37.    r.w := r.v.aw
  38.    r.h := r.v.ah
  39.    VRemove(ROOT, r.v, 1)
  40.    return r
  41. end
  42.  
  43. ##########################################################################
  44. # update_radio_bb() disallows resizing of a radio button object.
  45. ##########################################################################
  46. procedure update_radio_bb(object)
  47.    object.w := object.v.aw
  48.    object.h := object.v.ah
  49. end
  50.  
  51. ##########################################################################
  52. # draw_radio_button() draws the given radio button object.
  53. ##########################################################################
  54. procedure draw_radio_button(r)
  55.    VDraw(r.v)
  56.    return r
  57. end
  58.  
  59. ##########################################################################
  60. # load_radio_button() restores a radio button object from session code.
  61. ##########################################################################
  62. procedure load_radio_button(r, o)
  63.    r.alts := o.etc
  64.    r.v := Vradio_buttons(ROOT, r.x, r.y, APPWIN, r.alts, , r.id, V_DIAMOND_NO)
  65.    r.w := r.v.aw
  66.    r.h := r.v.ah
  67.    VRemove(ROOT, r.v, 1)
  68. end
  69.  
  70. ##########################################################################
  71. # save_radio_button() augments the record for saving a radio_button object.
  72. ##########################################################################
  73. procedure save_radio_button(r, o)
  74.    r.typ := "Choice"
  75.    r.num := *o.alts
  76.    r.etc := copy(o.alts)
  77.    return
  78. end
  79.  
  80. ##########################################################################
  81. # radio_button_atts() defines the attribute sheet template for a radio
  82. #                     button object.
  83. ##########################################################################
  84. procedure radio_button_atts()
  85.    local tempy
  86.  
  87.    RADIO_TALK := Vdialog(&window, PAD, PAD)
  88.    tempy := 0
  89.    VRegister(RADIO_TALK,
  90.       Vtext(&window, "ID:       ",, 1, TEXTCHARS, IDMASK), 0, tempy)
  91.    tempy +:= PAD
  92.    VRegister(RADIO_TALK,
  93.       Vtext(&window, "callback: ",, 3, TEXTCHARS, CBMASK), 0, tempy)
  94.    tempy +:= (3 * PAD)/2
  95.    VRegister(RADIO_TALK, Vtext(&window, "       x: ",, 4, 3, &digits), 0, tempy)
  96.    tempy +:= PAD
  97.    VRegister(RADIO_TALK, Vtext(&window, "       y: ",, 5, 3, &digits), 0, tempy)
  98.    VFormat(RADIO_TALK)
  99.    RB_starty := tempy
  100. end
  101.  
  102. ##########################################################################
  103. # display_radio_button_atts() displays the attribute sheet with the current
  104. #                             attributes for the given radio button instance.
  105. ##########################################################################
  106. procedure display_radio_button_atts(object)
  107.    local tempy, i, send_data, data, new, v, ok, nok, reg_list, ins_list, l
  108.    initial radio_button_atts()
  109.  
  110.    new := copy(object)
  111.    new.y -:= CANVASY
  112.    new.alts := copy(object.alts)
  113.  
  114.    repeat {
  115.       reg_list := []
  116.       ins_list := []
  117.       tempy := RB_starty
  118.  
  119.       # construct text fields and "add" and "del" buttons
  120.       every i := 0 to *new.alts do {
  121.          tempy +:= PAD
  122.          v := Vbutton(&window, "add", radio_cb, V_OK, , 28, 17)
  123.          VInsert(RADIO_TALK, v, 0, tempy + PAD / 2)
  124.          put(ins_list, v)
  125.          if i = 0 then
  126.             next
  127.          v := Vbutton(&window, "del", radio_cb, V_OK, , 28, 17)
  128.          VInsert(RADIO_TALK, v, 35 + TEXTWIDTH, tempy + 1)
  129.          put(ins_list, v)
  130.          v := Vtext(&window, "", , 5 + i, TEXTCHARS, LBMASK)
  131.          VRegister(RADIO_TALK, v, 35, tempy)
  132.          put(reg_list, v)
  133.          }
  134.  
  135.       # add "Okay" and "Cancel"
  136.       tempy +:= 2 * PAD
  137.       ok  := Vbutton(&window, "Okay", , V_OK, , 50, 30)
  138.       nok := Vbutton(&window, "Cancel", , V_CANCEL, , 50, 30)
  139.       VInsert(RADIO_TALK, ok, TEXTWIDTH / 2 - 30, tempy)
  140.       VInsert(RADIO_TALK, nok, TEXTWIDTH / 2 + 40, tempy)
  141.       put(ins_list, ok, nok)
  142.  
  143.       # post the dialog
  144.       RADIO_VIDGET := &null
  145.       VFormat(RADIO_TALK)
  146.       send_data := [new.id, new.proc, new.x, new.y] ||| new.alts
  147.       data := VOpenDialog(RADIO_TALK, , "radio_dialog", send_data, "Okay")
  148.       every VUnregister(RADIO_TALK, !reg_list)
  149.       every VRemove(RADIO_TALK, !ins_list, 1)
  150.  
  151.       if data === send_data then
  152.          fail                # cancelled
  153.  
  154.       # save new values
  155.       new.id    := strip(get(data))
  156.       new.proc  := strip(get(data))
  157.       new.x     := get(data)
  158.       new.y     := get(data)
  159.       every !new.alts := get(data)
  160.  
  161.       # if "add" or "del" was pressed, process it and loop to re-post dialog
  162.       if \RADIO_VIDGET then {
  163.          l := []
  164.          every v := reg_list[1 to *new.alts] do {
  165.             if v.ay - PAD < RADIO_VIDGET.ay-1 < v.ay then
  166.                put(l, "")
  167.             if v.ay ~= RADIO_VIDGET.ay-1 then
  168.                put(l, v.data)
  169.          }
  170.          if RADIO_VIDGET.ay-1 > reg_list[*new.alts].ay | *l = 0 then
  171.             put(l, "")
  172.          new.alts := l
  173.          next
  174.       }
  175.  
  176.       # check for legal field values
  177.       if illegal(new.id, "ID", "s") |
  178.          illegal(new.proc, "Callback", "p") |
  179.          illegal(new.x, "X", "i") |
  180.          illegal(new.y, "Y", "i")
  181.       then
  182.          next
  183.  
  184.       # everything is valid
  185.       object.proc := new.proc
  186.       object.id := new.id
  187.       object.alts := new.alts
  188.  
  189.       unfocus_object(object)
  190.       EraseArea(object.x, object.y, object.w, object.h)
  191.  
  192.       object.v := Vradio_buttons(ROOT,
  193.          object.x, object.y, APPWIN, new.alts, , object.v.id, V_DIAMOND_NO)
  194.       object.w := object.v.aw
  195.       object.h := object.v.ah
  196.       VRemove(ROOT, object.v, 1)
  197.  
  198.       move_object(object, new.x, new.y + CANVASY, object.w, object.h)
  199.       focus_object(object)
  200.       break
  201.    }
  202. end
  203.  
  204. ##########################################################################
  205. # radio_cb is called when an "add" or "del" button is pressed.
  206. ##########################################################################
  207. procedure radio_cb(v)
  208.    RADIO_VIDGET := v
  209. end
  210.