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 / vibtext.icn < prev   
Text File  |  2000-07-29  |  6KB  |  164 lines

  1. ############################################################################
  2. #
  3. #  vibtext.icn -- procedures for defining a text object
  4. #
  5. ############################################################################
  6. #
  7. #   This file is in the public domain.
  8. #
  9. ############################################################################
  10.  
  11. $include "vdefns.icn"
  12. $include "vibdefn.icn"
  13.  
  14. ##########################################################################
  15. # text_input_obj:
  16. #    v       : vidget used for drawing text input object
  17. #    proc    : name of user callback procedure
  18. #    id      : unique means of identifying instance
  19. #    x,y,w,h : bounding box
  20. #    label   : label of text input object
  21. #    value   : (editable) value of text input object
  22. #    length  : max number of chars that value can hold
  23. #    focus   : should focus lines be drawn around this object?
  24. ##########################################################################
  25. record text_input_obj(v, proc, id, x, y, w, h, label, value, length, focus)
  26.  
  27. ##########################################################################
  28. # create_text_input() creates a text instance and draws the text object if
  29. #                     it is a first class object.
  30. ##########################################################################
  31. procedure create_text_input(x, y, label, value, length)
  32.    local r, id
  33.  
  34.    id := next_id("text_input")
  35.    r := text_input_obj(, "text_input_cb" || id, "text_input" || id,
  36.                         x, y, 0, 0, label, value, length, 0)
  37.    r.v := Vtext(ROOT, x, y, APPWIN, label || "\\=" || value, , id, length)
  38.    r.w := r.v.aw
  39.    r.h := r.v.ah
  40.    VRemove(ROOT, r.v, 1)
  41.    return r
  42. end
  43.  
  44. ##########################################################################
  45. # draw_text_input() draws the given text object.
  46. ##########################################################################
  47. procedure draw_text_input(r)
  48.    r.length := r.v.MaxChars +:= (r.w - r.v.aw) / VFWidth
  49.    VResize(r.v)
  50.    VDraw(r.v)
  51.    return r
  52. end
  53.  
  54. ##########################################################################
  55. # update_text_input_bb() makes resizing work a character at a time.
  56. ##########################################################################
  57. procedure update_text_input_bb(object)
  58.    local wxv, n
  59.  
  60.    wxv := object.v.aw - VFWidth * object.v.MaxChars    # width excluding value
  61.    n := (object.w - wxv) / VFWidth            # num chars for value
  62.    n <:= 1
  63.    n <:= *object.value
  64.    object.w := wxv + VFWidth * n    # force width to char boundary
  65.    object.h := object.v.ah        # disallow height change
  66. end
  67.  
  68. ##########################################################################
  69. # load_text_input() restores a text object from session code.
  70. ##########################################################################
  71. procedure load_text_input(r, o)
  72.    o.lbl ? {
  73.       r.label := tab(find("\\\\="))
  74.       move(3)
  75.       r.value := tab(0)
  76.       }
  77.    r.length := o.num
  78.    r.v := Vtext(ROOT, r.x,r.y, APPWIN, r.label||"\\="||r.value,, r.id, r.length)
  79.    r.w := r.v.aw
  80.    r.h := r.v.ah
  81.    VRemove(ROOT, r.v, 1)
  82. end
  83.  
  84. ##########################################################################
  85. # save_text_input() augments the record for saving a text_input object.
  86. ##########################################################################
  87. procedure save_text_input(r, o)
  88.    r.typ := "Text"
  89.    r.lbl := image(o.label)[2:-1] || "\\\\=" || image(o.value)[2:-1]
  90.    r.num := o.length
  91.    return
  92. end
  93.  
  94. ##########################################################################
  95. # display_text_input_atts() displays the attribute sheet with the current
  96. #                           attributes for the given text instance.
  97. ##########################################################################
  98. procedure display_text_input_atts(object)
  99.    local t
  100.  
  101.    t := table()
  102.    t["a_id"]        := object.id
  103.    t["b_callback"]    := object.proc
  104.    t["c_x"]        := object.x
  105.    t["d_y"]        := object.y - CANVASY
  106.    t["e_label"]        := object.label
  107.    t["f_value"]        := object.value
  108.    t["g_length"]    := object.length
  109.  
  110.    repeat {
  111.       if text_dialog(t) == "Cancel" then
  112.          fail
  113.  
  114.       if illegal(t["a_id"], "ID", "s") |
  115.          illegal(t["b_callback"], "Callback", "p") |
  116.          illegal(t["c_x"], "X", "i") |
  117.          illegal(t["d_y"], "Y", "i") |
  118.          illegal(t["e_label"], "Label", "l") |
  119.          illegal(t["f_value"], "Value", "l") |
  120.          illegal(t["g_length"], "Length", 1) |
  121.          illegal(t["g_length"], "Length", *t["f_value"])
  122.       then
  123.          next
  124.  
  125.       object.id        := t["a_id"]
  126.       object.proc    := t["b_callback"]
  127.       object.label    := t["e_label"]
  128.       object.value    := t["f_value"]
  129.       object.length    := t["g_length"]
  130.  
  131.       unfocus_object(object)
  132.       EraseArea(object.x, object.y, object.w, object.h)
  133.  
  134.       object.v.MaxChars := object.length
  135.       object.v.s := object.label
  136.       VSetState(object.v, object.value)
  137.       VResize(object.v)
  138.       object.w := object.v.aw
  139.  
  140.       move_object(object, t["c_x"], t["d_y"] + CANVASY)
  141.       focus_object(object)
  142.       break
  143.    }
  144. end
  145.  
  146. #===<<vib:begin>>===    modify using vib; do not remove this marker line
  147. procedure text_dialog(win, deftbl)
  148. static dstate
  149. initial dstate := dsetup(win,
  150.    ["text_dialog:Sizer::1:0,0,460,230:",],
  151.    ["_cancel:Button:regular::250,180,50,30:Cancel",],
  152.    ["_okay:Button:regular:-1:180,180,50,30:Okay",],
  153.    ["a_id:Text::40:13,14,360,19:ID:       \\=",],
  154.    ["b_callback:Text::40:13,35,360,19:callback: \\=",],
  155.    ["c_x:Text::3:13,62,101,19:       x: \\=",],
  156.    ["d_y:Text::3:13,83,101,19:       y: \\=",],
  157.    ["e_label:Text::50:13,109,430,19:   label: \\=",],
  158.    ["f_value:Text::50:13,130,430,19:   value: \\=",],
  159.    ["g_length:Text::3:258,83,185,19:maximum value length: \\=",],
  160.    )
  161. return dpopup(win, deftbl, dstate)
  162. end
  163. #===<<vib:end>>===    end of section maintained by vib
  164.