0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Controller
|
|
14 |
instanceVariableNames:'model view sensor'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
Controller comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
Controllers can be used to controll the user-interactions
|
|
26 |
to a Model which is shown in a view. For very simple views,
|
|
27 |
(and due to the evolution of Smalltalk/X) many view-classes have
|
|
28 |
the controller function integrated.
|
|
29 |
|
|
30 |
Instance variables:
|
|
31 |
view aView the view I controll
|
|
32 |
model aModel the model which is to be worked on
|
|
33 |
|
3
|
34 |
$Header: /cvs/stx/stx/libview/Controller.st,v 1.2 1993-10-13 00:44:50 claus Exp $
|
0
|
35 |
written summer 92 by claus
|
|
36 |
'!
|
|
37 |
|
|
38 |
!Controller methodsFor:'initialize / release'!
|
|
39 |
|
|
40 |
initialize
|
|
41 |
"initialize the controller; subclasses should redefine
|
|
42 |
this and include a super initialize for proper initialization."
|
|
43 |
|
|
44 |
^ self
|
|
45 |
!
|
|
46 |
|
|
47 |
release
|
|
48 |
view controller:nil.
|
|
49 |
view := nil.
|
|
50 |
model := nil
|
|
51 |
! !
|
|
52 |
|
|
53 |
!Controller methodsFor:'accessing'!
|
|
54 |
|
|
55 |
view:aView
|
|
56 |
"set my view"
|
|
57 |
|
|
58 |
view notNil ifTrue:[
|
|
59 |
model notNil ifTrue:[
|
|
60 |
model removeDependent:view
|
|
61 |
]
|
|
62 |
].
|
|
63 |
view := aView.
|
|
64 |
model notNil ifTrue:[
|
|
65 |
model addDependent:view
|
|
66 |
].
|
|
67 |
sensor := WindowSensor new.
|
|
68 |
sensor view:view
|
|
69 |
!
|
|
70 |
|
|
71 |
view
|
|
72 |
"return my view"
|
|
73 |
|
|
74 |
^ view
|
|
75 |
!
|
|
76 |
|
|
77 |
model:aModel
|
|
78 |
"set my model"
|
|
79 |
|
|
80 |
model notNil ifTrue:[
|
|
81 |
model removeDependent:view "self"
|
|
82 |
].
|
|
83 |
model := aModel.
|
|
84 |
model notNil ifTrue:[model addDependent:view]
|
|
85 |
!
|
|
86 |
|
|
87 |
model
|
|
88 |
"return my model"
|
|
89 |
|
|
90 |
^ view model
|
|
91 |
!
|
|
92 |
|
|
93 |
sensor:aSensor
|
|
94 |
sensor := aSensor
|
|
95 |
!
|
|
96 |
|
|
97 |
sensor
|
|
98 |
"return my sensor"
|
|
99 |
|
|
100 |
^ sensor
|
|
101 |
! !
|
|
102 |
|
|
103 |
!Controller methodsFor:'event processing'!
|
|
104 |
|
|
105 |
process
|
|
106 |
|damage event type|
|
|
107 |
|
|
108 |
[sensor hasDamage] whileTrue:[
|
|
109 |
damage := sensor nextDamage.
|
|
110 |
'controller processing expose' printNewline.
|
|
111 |
view exposeX:damage left y:damage top
|
|
112 |
width:damage width height:damage height.
|
|
113 |
].
|
|
114 |
[sensor hasEvents] whileTrue:[
|
|
115 |
'controller processing event' printNewline.
|
|
116 |
event := sensor nextEvent.
|
|
117 |
type := event at:1.
|
|
118 |
type == #buttonPress ifTrue:[
|
|
119 |
view buttonPress:(event at:2)
|
|
120 |
x:(event at:3)
|
|
121 |
y:(event at:4)
|
|
122 |
] ifFalse:[
|
|
123 |
type == #buttonRelease ifTrue:[
|
|
124 |
view buttonRelease:(event at:2)
|
|
125 |
x:(event at:3)
|
|
126 |
y:(event at:4)
|
|
127 |
] ifFalse:[
|
|
128 |
type == #keyPress ifTrue:[
|
|
129 |
view keyPress:(event at:2)
|
|
130 |
x:(event at:3)
|
|
131 |
y:(event at:4)
|
|
132 |
] ifFalse:[
|
|
133 |
'unknown event: ' print.
|
|
134 |
type printNewline
|
|
135 |
]
|
|
136 |
]
|
|
137 |
]
|
|
138 |
]
|
|
139 |
! !
|
|
140 |
|
|
141 |
!Controller methodsFor:'controlled view events'!
|
|
142 |
|
|
143 |
sizeChanged:how of:aView
|
|
144 |
"a views size has changed - let it handle it itself"
|
|
145 |
|
|
146 |
aView sizeChanged:how
|
|
147 |
!
|
|
148 |
|
|
149 |
created:aView
|
|
150 |
"a view has been created"
|
|
151 |
|
|
152 |
^ self
|
|
153 |
!
|
|
154 |
|
|
155 |
buttonPress:button x:x y:y in:aView
|
|
156 |
"a button event happened in aView"
|
|
157 |
|
|
158 |
aView buttonPress:button x:x y:y
|
|
159 |
!
|
|
160 |
|
|
161 |
buttonShiftPress:button x:x y:y in:aView
|
|
162 |
"a button event happened in aView"
|
|
163 |
|
|
164 |
^ self buttonPress:button x:x y:y in:aView
|
|
165 |
!
|
|
166 |
|
|
167 |
buttonMultiPress:button x:x y:y in:aView
|
|
168 |
"a button event happened in aView"
|
|
169 |
|
|
170 |
^ self buttonPress:button x:x y:y in:aView
|
|
171 |
!
|
|
172 |
|
|
173 |
buttonRelease:button x:x y:y in:aView
|
|
174 |
"a button event happened in aView"
|
|
175 |
|
|
176 |
aView buttonRelease:button x:x y:y
|
|
177 |
!
|
|
178 |
|
|
179 |
buttonMotion:state x:x y:y in:aView
|
|
180 |
"a button event happened in aView"
|
|
181 |
|
|
182 |
aView buttonMotion:state x:x y:y
|
|
183 |
!
|
|
184 |
|
|
185 |
keyPress:key x:x y:y in:aView
|
|
186 |
"a key event happened in aView"
|
|
187 |
|
|
188 |
aView keyPress:key x:x y:y
|
|
189 |
!
|
|
190 |
|
|
191 |
pointerEnter:state x:x y:y in:aView
|
|
192 |
"mouse entered view"
|
|
193 |
|
|
194 |
aView pointerEnter:state x:x y:y
|
|
195 |
!
|
|
196 |
|
|
197 |
pointerLeave:state in:aView
|
|
198 |
"mouse left view"
|
|
199 |
|
|
200 |
aView pointerLeave:state
|
|
201 |
!
|
|
202 |
|
|
203 |
focusIn:aView
|
|
204 |
"a view got keyboard"
|
|
205 |
|
|
206 |
^ self
|
|
207 |
!
|
|
208 |
|
|
209 |
focusOut:aView
|
|
210 |
"a view lost keyboard"
|
|
211 |
|
|
212 |
^ self
|
|
213 |
! !
|