summaryrefslogtreecommitdiff
path: root/ipl/gpacks/vib/vibrect.icn
blob: 5d9875742cf8c2a6fad2b47cffb56c606c6aebf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
############################################################################
#
#  vibrect.icn -- procedures for defining an area object
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################

$include "vibdefn.icn"

##########################################################################
# rect_obj:
#    v       : vidget used for drawing rectangle
#    proc    : name of user callback procedure
#    id      : unique means of identifying a rectangle instance
#    x,y,w,h : bounding box
#    style   : invisible, sunken, grooved, raised
#    focus   : should focus lines be drawn around this object?
##########################################################################
record rect_obj(v, proc, id, x, y, w, h, style, focus)

##########################################################################
# create_rect() creates a rect instance and draws the rect if
#               it is a first class object.
##########################################################################
procedure create_rect(x, y, w, h, style)
   local r, id

   id := next_id("region")
   r := rect_obj(, "region_cb" || id, "region" || id, x, y, w, h, style, 0)
   r.v := Vpane(ROOT, x, y, APPWIN, , id, style, w, h)
   VRemove(ROOT, r.v, 1)
   return r
end

##########################################################################
# draw_rect() draws the given rect instance.
##########################################################################
procedure draw_rect(r)
   if r.style == "invisible" then {
      WAttrib(APPWIN, "linestyle=dashed")
      DrawRectangle(APPWIN, r.x, r.y, r.w - 1, r.h - 1)
      WAttrib(APPWIN, "linestyle=solid")
   }
   else
      VDraw(r.v)
   return r
end

##########################################################################
# load_rect() restores a rect object from session code.
##########################################################################
procedure load_rect(r, o)
   if o.sty ~== "" then
      r.style := o.sty
   else if integer(o.num) > 0 then
      r.style := "grooved"
   else
      r.style := "invisible"
   r.v := Vpane(ROOT, r.x, r.y, APPWIN, , r.id, r.style, r.w, r.h)
   VRemove(ROOT, r.v, 1)
end

##########################################################################
# save_rect() augments the record for saving a rect object.
##########################################################################
procedure save_rect(r, o)
   r.typ := "Rect"
   r.sty := o.style
   return
end

##########################################################################
# display_rect_atts() displays the attribute sheet with the current
#                     attributes for the given rect instance.
##########################################################################
procedure display_rect_atts(object)
   local t

   t := table()
   t["_style"]		:= object.style
   t["a_id"]		:= object.id
   t["b_callback"]	:= object.proc
   t["c_x"]		:= object.x
   t["d_y"]		:= object.y - CANVASY
   t["e_width"]		:= object.w
   t["f_height"]	:= object.h

   repeat {
      if rect_dialog(t) == "Cancel" then
         fail

      if illegal(t["a_id"], "ID", "s") |
         illegal(t["b_callback"], "Callback", "p") |
         illegal(t["c_x"], "X", "i") |
         illegal(t["d_y"], "Y", "i") |
         illegal(t["e_width"], "Width", MIN_W) |
         illegal(t["f_height"], "Height", MIN_H)
      then
         next

      object.v.style := object.style := t["_style"]
      object.id		:= t["a_id"]
      object.proc	:= t["b_callback"]
      unfocus_object(object)
      move_object(object,
         t["c_x"], t["d_y"] + CANVASY, t["e_width"], t["f_height"])
      focus_object(object)
      break
   }
end



#===<<vib:begin>>===	modify using vib; do not remove this marker line
procedure rect_dialog(win, deftbl)
static dstate
initial dstate := dsetup(win,
   ["rect_dialog:Sizer::1:0,0,388,216:",],
   ["_cancel:Button:regular::216,167,50,30:Cancel",],
   ["_okay:Button:regular:-1:146,167,50,30:Okay",],
   ["_style:Choice::4:281,62,92,84:",,
      ["invisible","sunken","grooved","raised"]],
   ["a_id:Text::40:13,14,360,19:ID:       \\=",],
   ["b_callback:Text::40:13,35,360,19:callback: \\=",],
   ["c_x:Text::3:13,62,101,19:       x: \\=",],
   ["d_y:Text::3:13,88,101,19:       y: \\=",],
   ["e_width:Text::3:132,62,101,19:   width: \\=",],
   ["f_height:Text::3:132,88,101,19:  height: \\=",],
   )
return dpopup(win, deftbl, dstate)
end
#===<<vib:end>>===	end of section maintained by vib