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

  1. ############################################################################
  2. #
  3. #  vibrect.icn -- procedures for defining an area object
  4. #
  5. ############################################################################
  6. #
  7. #   This file is in the public domain.
  8. #
  9. ############################################################################
  10.  
  11. $include "vibdefn.icn"
  12.  
  13. ##########################################################################
  14. # rect_obj:
  15. #    v       : vidget used for drawing rectangle
  16. #    proc    : name of user callback procedure
  17. #    id      : unique means of identifying a rectangle instance
  18. #    x,y,w,h : bounding box
  19. #    style   : invisible, sunken, grooved, raised
  20. #    focus   : should focus lines be drawn around this object?
  21. ##########################################################################
  22. record rect_obj(v, proc, id, x, y, w, h, style, focus)
  23.  
  24. ##########################################################################
  25. # create_rect() creates a rect instance and draws the rect if
  26. #               it is a first class object.
  27. ##########################################################################
  28. procedure create_rect(x, y, w, h, style)
  29.    local r, id
  30.  
  31.    id := next_id("region")
  32.    r := rect_obj(, "region_cb" || id, "region" || id, x, y, w, h, style, 0)
  33.    r.v := Vpane(ROOT, x, y, APPWIN, , id, style, w, h)
  34.    VRemove(ROOT, r.v, 1)
  35.    return r
  36. end
  37.  
  38. ##########################################################################
  39. # draw_rect() draws the given rect instance.
  40. ##########################################################################
  41. procedure draw_rect(r)
  42.    if r.style == "invisible" then {
  43.       WAttrib(APPWIN, "linestyle=dashed")
  44.       DrawRectangle(APPWIN, r.x, r.y, r.w - 1, r.h - 1)
  45.       WAttrib(APPWIN, "linestyle=solid")
  46.    }
  47.    else
  48.       VDraw(r.v)
  49.    return r
  50. end
  51.  
  52. ##########################################################################
  53. # load_rect() restores a rect object from session code.
  54. ##########################################################################
  55. procedure load_rect(r, o)
  56.    if o.sty ~== "" then
  57.       r.style := o.sty
  58.    else if integer(o.num) > 0 then
  59.       r.style := "grooved"
  60.    else
  61.       r.style := "invisible"
  62.    r.v := Vpane(ROOT, r.x, r.y, APPWIN, , r.id, r.style, r.w, r.h)
  63.    VRemove(ROOT, r.v, 1)
  64. end
  65.  
  66. ##########################################################################
  67. # save_rect() augments the record for saving a rect object.
  68. ##########################################################################
  69. procedure save_rect(r, o)
  70.    r.typ := "Rect"
  71.    r.sty := o.style
  72.    return
  73. end
  74.  
  75. ##########################################################################
  76. # display_rect_atts() displays the attribute sheet with the current
  77. #                     attributes for the given rect instance.
  78. ##########################################################################
  79. procedure display_rect_atts(object)
  80.    local t
  81.  
  82.    t := table()
  83.    t["_style"]        := object.style
  84.    t["a_id"]        := object.id
  85.    t["b_callback"]    := object.proc
  86.    t["c_x"]        := object.x
  87.    t["d_y"]        := object.y - CANVASY
  88.    t["e_width"]        := object.w
  89.    t["f_height"]    := object.h
  90.  
  91.    repeat {
  92.       if rect_dialog(t) == "Cancel" then
  93.          fail
  94.  
  95.       if illegal(t["a_id"], "ID", "s") |
  96.          illegal(t["b_callback"], "Callback", "p") |
  97.          illegal(t["c_x"], "X", "i") |
  98.          illegal(t["d_y"], "Y", "i") |
  99.          illegal(t["e_width"], "Width", MIN_W) |
  100.          illegal(t["f_height"], "Height", MIN_H)
  101.       then
  102.          next
  103.  
  104.       object.v.style := object.style := t["_style"]
  105.       object.id        := t["a_id"]
  106.       object.proc    := t["b_callback"]
  107.       unfocus_object(object)
  108.       move_object(object,
  109.          t["c_x"], t["d_y"] + CANVASY, t["e_width"], t["f_height"])
  110.       focus_object(object)
  111.       break
  112.    }
  113. end
  114.  
  115.  
  116.  
  117. #===<<vib:begin>>===    modify using vib; do not remove this marker line
  118. procedure rect_dialog(win, deftbl)
  119. static dstate
  120. initial dstate := dsetup(win,
  121.    ["rect_dialog:Sizer::1:0,0,388,216:",],
  122.    ["_cancel:Button:regular::216,167,50,30:Cancel",],
  123.    ["_okay:Button:regular:-1:146,167,50,30:Okay",],
  124.    ["_style:Choice::4:281,62,92,84:",,
  125.       ["invisible","sunken","grooved","raised"]],
  126.    ["a_id:Text::40:13,14,360,19:ID:       \\=",],
  127.    ["b_callback:Text::40:13,35,360,19:callback: \\=",],
  128.    ["c_x:Text::3:13,62,101,19:       x: \\=",],
  129.    ["d_y:Text::3:13,88,101,19:       y: \\=",],
  130.    ["e_width:Text::3:132,62,101,19:   width: \\=",],
  131.    ["f_height:Text::3:132,88,101,19:  height: \\=",],
  132.    )
  133. return dpopup(win, deftbl, dstate)
  134. end
  135. #===<<vib:end>>===    end of section maintained by vib
  136.