author | Claus Gittinger <cg@exept.de> |
Wed, 23 Aug 2006 01:58:25 +0200 | |
changeset 2165 | 308101564aa0 |
parent 1789 | f52f0a0d8448 |
child 2811 | 2d26a7061949 |
permissions | -rw-r--r-- |
1789 | 1 |
"{ Package: 'stx:libview2' }" |
2 |
||
278 | 3 |
TranslatingWrapper subclass:#LayoutWrapper |
4 |
instanceVariableNames:'layout' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
1789 | 7 |
category:'Compatibility-ST80-Graphics-Display Objects' |
278 | 8 |
! |
9 |
||
365 | 10 |
!LayoutWrapper class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
Notice: |
|
15 |
this class was implemented using protocol information |
|
16 |
from alpha testers, from reading PD programs and |
|
17 |
from the Hopkins/Horan book. |
|
18 |
- it may not be complete or compatible to the corresponding ST-80 class. |
|
19 |
If you encounter any incompatibilities, please forward a note |
|
20 |
describing the incompatibility verbal (i.e. no code) to the ST/X team. |
|
21 |
||
22 |
[author:] |
|
23 |
Claus Gittinger |
|
24 |
" |
|
25 |
||
26 |
! |
|
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
27 |
|
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
28 |
examples |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
29 |
" |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
30 |
[exBegin] |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
31 |
|t view wrapper| |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
32 |
|
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
33 |
t := StandardSystemView extent:200@200. |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
34 |
|
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
35 |
view := View new. |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
36 |
view viewBackground:Color red. |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
37 |
|
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
38 |
wrapper := LayoutWrapper new. |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
39 |
wrapper layout:(LayoutFrame new |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
40 |
leftFraction:0.2; |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
41 |
rightFraction:0.8; |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
42 |
topFraction:0.2; |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
43 |
bottomFraction:0.8). |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
44 |
wrapper component:view. |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
45 |
|
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
46 |
t addComponent:wrapper. |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
47 |
|
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
48 |
t open |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
49 |
[exEnd] |
323 | 50 |
[exBegin] |
51 |
|top frame1 view1 frame2 view2| |
|
52 |
||
53 |
top := StandardSystemView new. |
|
54 |
frame1 := LayoutWrapper new. |
|
55 |
frame1 layout:(0.1@0.1 corner:0.9@0.9) asLayout. |
|
56 |
top addSubView:frame1. |
|
57 |
||
58 |
view1 := View new. |
|
59 |
view1 viewBackground:Color red. |
|
60 |
frame1 component:view1. |
|
61 |
||
62 |
frame2 := LayoutWrapper new. |
|
63 |
frame2 layout:(0.1@0.1 corner:0.9@0.9) asLayout. |
|
64 |
view1 addSubView:frame2. |
|
65 |
||
66 |
view2 := View new. |
|
67 |
view2 viewBackground:Color green. |
|
68 |
frame2 component:view2. |
|
69 |
||
70 |
top openWithExtent:200@200 |
|
71 |
[exEnd] |
|
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
72 |
" |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
73 |
! ! |
278 | 74 |
|
365 | 75 |
!LayoutWrapper class methodsFor:'instance creation'! |
278 | 76 |
|
77 |
on:aComponent in:aLayout |
|
78 |
"create and return a layoutWrapper, which controls |
|
79 |
aComponent bounds using aLayout. |
|
80 |
The layout argument may be: |
|
81 |
nil - no constraint |
|
82 |
Point - origin shift |
|
83 |
Rectangle - origin shift & extent |
|
84 |
Layout - full control" |
|
85 |
||
86 |
^ (self on:aComponent) layout:aLayout |
|
87 |
||
88 |
"Created: 26.5.1996 / 16:18:44 / cg" |
|
89 |
"Modified: 26.5.1996 / 16:34:04 / cg" |
|
90 |
! ! |
|
91 |
||
92 |
!LayoutWrapper methodsFor:'accessing'! |
|
93 |
||
323 | 94 |
bounds:newBounds |
95 |
"/ Transcript showCR:newBounds. |
|
96 |
bounds := newBounds. |
|
97 |
self layoutChanged |
|
98 |
||
99 |
"Created: 19.7.1996 / 20:10:09 / cg" |
|
100 |
"Modified: 19.7.1996 / 21:20:42 / cg" |
|
101 |
! |
|
102 |
||
278 | 103 |
layout |
104 |
"return layout" |
|
105 |
||
106 |
^ layout |
|
107 |
||
108 |
"Created: 26.5.1996 / 16:18:11 / cg" |
|
109 |
! |
|
110 |
||
111 |
layout:something |
|
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
112 |
"set the layout" |
278 | 113 |
|
114 |
layout := something. |
|
323 | 115 |
self layoutChanged |
278 | 116 |
|
117 |
"Created: 26.5.1996 / 16:18:11 / cg" |
|
323 | 118 |
"Modified: 19.7.1996 / 20:15:20 / cg" |
119 |
! ! |
|
120 |
||
121 |
!LayoutWrapper methodsFor:'private'! |
|
122 |
||
123 |
layoutChanged |
|
124 |
|subBounds| |
|
125 |
||
126 |
component notNil ifTrue:[ |
|
127 |
layout notNil ifTrue:[ |
|
128 |
subBounds := (layout |
|
129 |
rectangleRelativeTo:bounds |
|
130 |
preferred:bounds) rounded. |
|
131 |
] ifFalse:[ |
|
132 |
subBounds := bounds |
|
133 |
]. |
|
134 |
||
135 |
origin := subBounds origin. |
|
136 |
"/ Transcript show:layout displayString; show:'subbounds: '; showCR:subBounds. |
|
137 |
component bounds:subBounds. |
|
138 |
] |
|
139 |
||
140 |
"Created: 19.7.1996 / 20:15:05 / cg" |
|
141 |
"Modified: 19.7.1996 / 21:20:46 / cg" |
|
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
142 |
! ! |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
143 |
|
321 | 144 |
!LayoutWrapper methodsFor:'queries'! |
145 |
||
146 |
isLayoutWrapper |
|
147 |
^ true |
|
148 |
||
149 |
"Created: 19.7.1996 / 17:51:16 / cg" |
|
323 | 150 |
! |
151 |
||
152 |
preferredBounds |
|
153 |
|b w h lw lh| |
|
154 |
||
155 |
bounds := component preferredBounds. |
|
156 |
layout isNil ifTrue:[^ bounds]. |
|
157 |
||
158 |
w := bounds width. |
|
159 |
h := bounds height. |
|
160 |
||
161 |
"/ now, inverse apply the layouts values |
|
162 |
||
163 |
lw := layout rightFraction - layout leftFraction. |
|
164 |
lw ~~ 0 ifTrue:[ |
|
165 |
lw := w * (1 / lw) |
|
166 |
]. |
|
167 |
lh := layout bottomFraction - layout topFraction. |
|
168 |
lh ~~ 0 ifTrue:[ |
|
169 |
lh := h * (1 / lh) |
|
170 |
]. |
|
171 |
lw := lw + layout rightOffset - layout leftOffset. |
|
172 |
lh := lh + layout bottomOffset - layout topOffset. |
|
173 |
||
174 |
^ 0@0 corner:(lw rounded @ lh rounded) |
|
175 |
||
176 |
"Created: 19.7.1996 / 17:51:16 / cg" |
|
177 |
"Modified: 19.7.1996 / 20:08:51 / cg" |
|
321 | 178 |
! ! |
179 |
||
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
180 |
!LayoutWrapper methodsFor:'view protocol mimicri'! |
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
181 |
|
323 | 182 |
computeOrigin |
183 |
"return my origin" |
|
184 |
||
185 |
^ 0@0 |
|
186 |
||
187 |
"Created: 19.7.1996 / 20:05:37 / cg" |
|
188 |
! |
|
189 |
||
190 |
origin:org corner:corn |
|
191 |
|newLayout l r t b lF rF tF bF lO rO tO bO| |
|
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
192 |
|
323 | 193 |
newLayout := LayoutFrame new. |
194 |
l := org x. |
|
195 |
l isInteger ifTrue:[ |
|
196 |
lO := l. |
|
197 |
lF := 0.0 |
|
198 |
] ifFalse:[ |
|
199 |
lO := 0. |
|
200 |
lF := l |
|
201 |
]. |
|
202 |
r := corn x. |
|
203 |
r isInteger ifTrue:[ |
|
204 |
rO := r. |
|
205 |
rF := 0.0 |
|
206 |
] ifFalse:[ |
|
207 |
rO := 0. |
|
208 |
rF := r |
|
209 |
]. |
|
210 |
t := org y. |
|
211 |
t isInteger ifTrue:[ |
|
212 |
tO := t. |
|
213 |
tF := 0.0 |
|
214 |
] ifFalse:[ |
|
215 |
tO := 0. |
|
216 |
tF := t |
|
217 |
]. |
|
218 |
b := corn y. |
|
219 |
b isInteger ifTrue:[ |
|
220 |
bO := b. |
|
221 |
bF := 0.0 |
|
222 |
] ifFalse:[ |
|
223 |
bO := 0. |
|
224 |
bF := b |
|
225 |
]. |
|
292
60fbf13dfc8c
prepare for view-component integration
Claus Gittinger <cg@exept.de>
parents:
278
diff
changeset
|
226 |
|
323 | 227 |
newLayout |
228 |
leftFraction:lF offset:lO; |
|
229 |
rightFraction:rF offset:rO; |
|
230 |
topFraction:tF offset:tO; |
|
231 |
bottomFraction:bF offset:bO. |
|
232 |
||
233 |
self layout:newLayout |
|
234 |
||
235 |
"Modified: 19.7.1996 / 21:22:11 / cg" |
|
278 | 236 |
! ! |
237 |
||
365 | 238 |
!LayoutWrapper class methodsFor:'documentation'! |
278 | 239 |
|
240 |
version |
|
1789 | 241 |
^ '$Header: /cvs/stx/stx/libview2/LayoutWrapper.st,v 1.6 2003-08-18 12:13:19 cg Exp $' |
278 | 242 |
! ! |