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

  1. ############################################################################
  2. #
  3. #  vibslidr.icn -- procedures for defining slider and scrollbar objects
  4. #
  5. ############################################################################
  6. #
  7. #   This file is in the public domain.
  8. #
  9. ############################################################################
  10.  
  11. $include "vibdefn.icn"
  12. $include "vdefns.icn"
  13.  
  14. ##########################################################################
  15. # slider_obj:
  16. #    v       : vidget used for drawing
  17. #    proc    : name of user callback procedure
  18. #    filter  : filter out dragging events?
  19. #    id      : unique identifier
  20. #    x,y,w,h : bounding box
  21. #    min     : min value of range
  22. #    max     : max value of range
  23. #    value   : current value within range
  24. #    typ     : "Slider" or "Scrollbar"
  25. #    focus   : should focus lines be drawn around this object?
  26. ##########################################################################
  27. record slider_obj(v, proc, filter, id, x, y, w, h, min, max, value, typ, focus)
  28.  
  29. ##########################################################################
  30. # create_slider() creates a slider instance and draws the slider.
  31. ##########################################################################
  32. procedure create_slider(x, y, w, h, typ, min, max, value, filter)
  33.    local r, id, prefix
  34.  
  35.    if typ == "Scrollbar" then
  36.       prefix := "sbar"
  37.    else
  38.       prefix := "slider"
  39.    id := next_id(prefix)
  40.  
  41.    r := slider_obj(, prefix || "_cb" || id, filter, prefix || id,
  42.        x, y, w, h, min, max, value, typ, 0)
  43.  
  44.    r.v := slider_vidget(id, typ, x, y, w, h)
  45.    VRemove(ROOT, r.v, 1)
  46.    return r
  47. end
  48.  
  49. ##########################################################################
  50. # slider_vidget() creates the appropriate vidget for a slider or scrollbar.
  51. ##########################################################################
  52. procedure slider_vidget(id, typ, x, y, w, h)
  53.    local dir
  54.  
  55.    dir := if w > h then "h" else "v"
  56.    return case dir || typ of {
  57.       "vSlider":     Vvert_slider(ROOT, x, y, APPWIN, , id, h, w, 1.0, 0.0)
  58.       "hSlider":     Vhoriz_slider(ROOT, x, y, APPWIN, , id, w, h)
  59.       "vScrollbar":  Vvert_scrollbar(ROOT, x, y, APPWIN, , id, h, w, 1.0, 0.0)
  60.       "hScrollbar":  Vhoriz_scrollbar(ROOT, x, y, APPWIN, , id, w, h)
  61.       }
  62. end
  63.  
  64. ##########################################################################
  65. # update_slider_bb() updates attributes in response to resizing.
  66. ##########################################################################
  67. procedure update_slider_bb(object)
  68.    if object.w > object.h then {
  69.       object.w <:= VSlider_MinAspect * VSlider_MinWidth
  70.       object.h >:= object.w / VSlider_MinAspect
  71.    }
  72.    else {
  73.       object.h <:= VSlider_MinAspect * VSlider_MinWidth
  74.       object.w >:= object.h / VSlider_MinAspect
  75.    }
  76. end
  77.  
  78. ##########################################################################
  79. # draw_slider() draws the given slider object.
  80. ##########################################################################
  81. procedure draw_slider(r)
  82.    VSetState(r.v, abs((r.value - r.min) / (real(r.max - r.min))))
  83.    VDraw(r.v)
  84.    return r
  85. end
  86.  
  87. ##########################################################################
  88. # load_slider() restores a slider object from session code.
  89. ##########################################################################
  90. procedure load_slider(r, o)
  91.    local dir
  92.  
  93.    r.filter := ("" ~== o.num)
  94.    r.typ := o.typ
  95.    o.lbl ? {
  96.       r.min := tab(upto(",")); move(1)
  97.       r.max := tab(upto(",")); move(1)
  98.       r.value := tab(0)
  99.       }
  100.  
  101.    r.v := slider_vidget(r.id, r.typ, r.x, r.y, r.w, r.h)
  102.    VRemove(ROOT, r.v, 1)
  103. end
  104.  
  105. ##########################################################################
  106. # save_slider() augments the record for saving a slider object.
  107. ##########################################################################
  108. procedure save_slider(r, o)
  109.    r.typ := o.typ
  110.    r.lbl := o.min || "," || o.max || "," || o.value
  111.    r.sty := if r.w > r.h then "h" else "v"
  112.    r.num := o.filter
  113.    return
  114. end
  115.  
  116. ##########################################################################
  117. # display_slider_atts() displays the attribute sheet with the current
  118. #                       attributes for the given slider instance.
  119. ##########################################################################
  120. procedure display_slider_atts(object)
  121.    local t, s
  122.  
  123.    t := table()
  124.    t["_filter"]        := object.filter
  125.    t["a_id"]        := object.id
  126.    t["b_callback"]    := object.proc
  127.    t["c_x"]        := object.x
  128.    t["d_y"]        := object.y - CANVASY
  129.    t["g_lefttop"]    := object.min
  130.    t["h_initial"]    := object.value
  131.    t["i_rightbot"]    := object.max
  132.  
  133.    if object.w > object.h then {
  134.       t["j_orientation"] := "horizontal"
  135.       t["e_length"]    := object.w
  136.       t["f_width"]    := object.h
  137.    }
  138.    else {
  139.       t["j_orientation"] := "vertical"
  140.       t["e_length"]    := object.h
  141.       t["f_width"]    := object.w
  142.    }
  143.  
  144.    repeat {
  145.       s := slider_dialog(t)
  146.       if s == "Cancel" then
  147.          fail
  148.  
  149.       if illegal(t["a_id"], "ID", "s") |
  150.          illegal(t["b_callback"], "Callback", "p") |
  151.          illegal(t["c_x"], "X", "i") |
  152.          illegal(t["d_y"], "Y", "i") |
  153.          illegal(t["f_width"], "Width", VSlider_MinWidth) |
  154.          illegal(t["e_length"], "Length", t["f_width"] * VSlider_MinAspect) |
  155.          illegal(t["g_lefttop"], "Left / Top", "n") |
  156.          illegal(t["h_initial"], "Initial", "n") |
  157.          illegal(t["i_rightbot"], "Right / Bottom", "n")
  158.       then
  159.          next
  160.  
  161.       if not ((t["g_lefttop"] <= t["h_initial"] <= t["i_rightbot"]) |
  162.          (t["g_lefttop"] >= t["h_initial"] >= t["i_rightbot"])) then {
  163.             Notice("Initial value is not between the two extremes")
  164.             next
  165.             }
  166.  
  167.       object.filter    := t["_filter"]
  168.       object.id        := t["a_id"]
  169.       object.proc    := t["b_callback"]
  170.       object.min    := t["g_lefttop"]
  171.       object.value    := t["h_initial"]
  172.       object.max    := t["i_rightbot"]
  173.       unfocus_object(object)
  174.       if t["j_orientation"] == "horizontal" then
  175.          move_object(object,
  176.             t["c_x"], t["d_y"] + CANVASY, t["e_length"], t["f_width"])
  177.       else
  178.          move_object(object,
  179.             t["c_x"], t["d_y"] + CANVASY, t["f_width"], t["e_length"])
  180.       focus_object(object)
  181.       break
  182.    }
  183. end
  184.  
  185. #===<<vib:begin>>===    modify using vib; do not remove this marker line
  186. procedure slider_dialog(win, deftbl)
  187. static dstate
  188. initial dstate := dsetup(win,
  189.    ["slider_dialog:Sizer::1:0,0,389,276:",],
  190.    ["_cancel:Button:regular::204,225,50,30:Cancel",],
  191.    ["_filter:Button:checkno:1:270,132,69,20:filter",],
  192.    ["_okay:Button:regular:-1:139,224,50,30:Okay",],
  193.    ["a_id:Text::40:13,14,360,19:ID:       \\=",],
  194.    ["b_callback:Text::40:13,35,360,19:callback: \\=",],
  195.    ["c_x:Text::3:13,62,101,19:       x: \\=",],
  196.    ["d_y:Text::3:13,83,101,19:       y: \\=",],
  197.    ["e_length:Text::3:13,109,101,19:  length: \\=",],
  198.    ["f_width:Text::3:13,130,101,19:   width: \\=",],
  199.    ["g_lefttop:Text::10:181,62,192,19:    top / left: \\=",],
  200.    ["h_initial:Text::10:181,83,192,19:       initial: \\=",],
  201.    ["i_rightbot:Text::10:181,104,192,19:bottom / right: \\=",],
  202.    ["j_orientation:Choice::2:15,156,99,42:",,
  203.       ["vertical","horizontal"]],
  204.    )
  205. return dpopup(win, deftbl, dstate)
  206. end
  207. #===<<vib:end>>===    end of section maintained by vib
  208.