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 / vibbttn.icn < prev    next >
Text File  |  2000-07-29  |  7KB  |  221 lines

  1. ############################################################################
  2. #
  3. #  vibbttn.icn -- procedures for defining a button object
  4. #
  5. ############################################################################
  6. #
  7. #   This file is in the public domain.
  8. #
  9. ############################################################################
  10.  
  11. $include "vibdefn.icn"
  12.  
  13. ##########################################################################
  14. # button_obj:
  15. #    v       : vidget used for drawing text input object
  16. #    proc    : name of user callback procedure
  17. #    id      : unique means of identifying instance
  18. #    x,y,w,h : bounding box
  19. #    label   : button label
  20. #    style   : button style
  21. #    toggle  : is this a toggle button?
  22. #    dflt    : is this button the default in a dialog box?
  23. #    focus   : should focus lines be drawn around this object?
  24. ##########################################################################
  25. record button_obj(v, proc, id, x, y, w, h,
  26.                   label, style, toggle, dflt, focus)
  27.  
  28.  
  29. ##########################################################################
  30. # create_button() creates a button instance and draws the button if
  31. #                 it is a first class object.
  32. ##########################################################################
  33. procedure create_button(x, y, w, h, label, style, toggle, dflt)
  34.    local r, id
  35.  
  36.    id := next_id("button")
  37.    /style := DEFAULT_BUTTON_STYLE
  38.    r := button_obj(, "button_cb" || id, "button" || id,
  39.                      x, y, w, h, label, style, toggle, dflt, 0)
  40.    r.v := Vbutton(ROOT, x, y, APPWIN, label, , id, style, w, h)
  41.    VRemove(ROOT, r.v, 1)
  42.    return r
  43. end
  44.  
  45. ##########################################################################
  46. # draw_button() draws the given button in that button's style.
  47. ##########################################################################
  48. procedure draw_button(r)
  49.    VResize(r.v, r.x, r.y, r.w, r.h)
  50.    VDraw(r.v)
  51.    if \r.dflt then
  52.       BevelRectangle(APPWIN, r.x - 4, r.y - 4, r.w + 8, r.h + 8, -2)
  53.    return r
  54. end
  55.  
  56. ##########################################################################
  57. # update_button_bb() updates various attributes of the button that
  58. #                    change when the button is resized, etc.
  59. ##########################################################################
  60. procedure update_button_bb(r)
  61.    local tempy, temph, vpad, hpad, sp, sz
  62.  
  63.    vpad := 4            # vertical padding
  64.    hpad := 7            # horizontal padding
  65.    sp := 11            # space between circle/box and text
  66.    r.w <:= MIN_W
  67.    r.h <:= MIN_H
  68.    case r.style of {
  69.       "check" | "circle" | "checkno" | "circleno": {
  70.          sz := integer(WAttrib(APPWIN, "fheight") * 0.75)
  71.          r.w <:= sz + sp + TextWidth(APPWIN, r.label) + hpad
  72.          r.h <:= WAttrib(APPWIN, "fheight") + vpad
  73.       }
  74.       "regular" | "regularno": {
  75.          r.w <:= TextWidth(APPWIN, r.label) + hpad
  76.          r.h <:= WAttrib(APPWIN, "fheight") + vpad
  77.       }
  78.       "xbox" | "xboxno": {
  79.          r.w <:= r.h
  80.          r.h <:= r.w
  81.          r.label := &null
  82.       }
  83.    }
  84. end
  85.  
  86. ##########################################################################
  87. # load_button() restores a button object from session code.
  88. ##########################################################################
  89. procedure load_button(r, o)
  90.    r.label := o.lbl
  91.    r.style := o.sty
  92.    case o.num of {
  93.       "1":    r.toggle := 1
  94.       "-1":    r.dflt := 1
  95.       }
  96.    r.v := Vbutton(ROOT, r.x, r.y, APPWIN, r.label, , r.id, r.style, r.w, r.h)
  97.    VRemove(ROOT, r.v, 1)
  98. end
  99.  
  100. ##########################################################################
  101. # load_xbox() makes an xbox button object from an old checkbox entry.
  102. ##########################################################################
  103. procedure load_xbox(r, o)
  104.    r.label := ""
  105.    r.style := "xbox"
  106.    r.toggle := 1
  107. end
  108.  
  109. ##########################################################################
  110. # save_button() augments the record for saving a button object.
  111. ##########################################################################
  112. procedure save_button(r, o)
  113.    r.typ := "Button"
  114.    r.lbl := o.label
  115.    r.sty := o.style
  116.    if \o.dflt then
  117.       r.num := -1
  118.    else
  119.       r.num := o.toggle
  120.    return
  121. end
  122.  
  123. ##########################################################################
  124. # display_button_atts() displays the attribute sheet with the current
  125. #                       attributes for the given button instance.
  126. ##########################################################################
  127. procedure display_button_atts(object)
  128.    local s, o, t, d
  129.  
  130.    d := object.dflt
  131.  
  132.    s := object.style
  133.    o := 1
  134.    if s[-2:0] == "no" then {
  135.       s := s[1:-2]
  136.       o := &null
  137.       }
  138.  
  139.    t := table()
  140.    t["_style"]        := s
  141.    t["_outline"]    := o
  142.    t["_toggle"]        := object.toggle
  143.    t["_dflt"]        := object.dflt
  144.    t["a_label"]        := object.label
  145.    t["b_id"]        := object.id
  146.    t["c_callback"]    := object.proc
  147.    t["d_x"]        := object.x
  148.    t["e_y"]        := object.y - CANVASY
  149.    t["f_width"]        := object.w
  150.    t["g_height"]    := object.h
  151.  
  152.    repeat {
  153.       if button_dialog(t) == "Cancel" then
  154.          fail
  155.  
  156.       if illegal(t["a_label"], "Label", "l") |
  157.          illegal(t["b_id"], "ID", "s") |
  158.          illegal(t["c_callback"], "Callback", "p") |
  159.          illegal(t["d_x"], "X", "i") |
  160.          illegal(t["e_y"], "Y", "i") |
  161.          illegal(t["f_width"], "Width", MIN_W) |
  162.          illegal(t["g_height"], "Height", MIN_H)
  163.       then
  164.          next
  165.  
  166.       if t["_style"] ? ="xbox" & *t["a_label"] > 0 then {
  167.          Notice("No text is allowed with xbox style")
  168.          next
  169.       }
  170.       if \t["_toggle"] & \t["_dflt"] then {
  171.         Notice("A toggle button cannot be a dialog default")
  172.         next
  173.       }
  174.  
  175.       object.style := t["_style"]
  176.       if /t["_outline"] then
  177.          object.style ||:= "no"
  178.  
  179.       object.dflt    := t["_dflt"]
  180.       object.toggle    := t["_toggle"]
  181.       object.label    := t["a_label"]
  182.       object.id        := t["b_id"]
  183.       object.proc    := t["c_callback"]
  184.  
  185.       object.v.style    := object.style
  186.       object.v.s    := object.label
  187.  
  188.       unfocus_object(object)
  189.       if /object.dflt & \d then            # remove default frame
  190.           EraseArea(object.x - 4, object.y - 4, object.w + 8, object.h + 8)
  191.       move_object(object,
  192.          t["d_x"], t["e_y"] + CANVASY, t["f_width"], t["g_height"])
  193.       focus_object(object)
  194.       break
  195.    }
  196. end
  197.  
  198. #===<<vib:begin>>===    modify using vib; do not remove this marker line
  199. procedure button_dialog(win, deftbl)
  200. static dstate
  201. initial dstate := dsetup(win,
  202.    ["button_dialog:Sizer::1:0,0,392,240:",],
  203.    ["_cancel:Button:regular::211,189,50,30:Cancel",],
  204.    ["_dflt:Button:check:1:245,148,125,20:dialog default",],
  205.    ["_okay:Button:regular:-1:141,189,50,30:Okay",],
  206.    ["_outline:Button:check:1:245,85,76,20:outline",],
  207.    ["_style:Choice::4:142,85,78,84:",,
  208.       ["regular","check","circle","xbox"]],
  209.    ["_toggle:Button:check:1:245,116,76,20:toggle",],
  210.    ["a_label:Text::40:13,14,360,19:label:    \\=",],
  211.    ["b_id:Text::40:13,35,360,19:ID:       \\=",],
  212.    ["c_callback:Text::40:13,56,360,19:callback: \\=",],
  213.    ["d_x:Text::3:13,85,101,19:       x: \\=",],
  214.    ["e_y:Text::3:13,106,101,19:       y: \\=",],
  215.    ["f_width:Text::3:13,131,101,19:   width: \\=",],
  216.    ["g_height:Text::3:13,152,101,19:  height: \\=",],
  217.    )
  218. return dpopup(win, deftbl, dstate)
  219. end
  220. #===<<vib:end>>===    end of section maintained by vib
  221.