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