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