"
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
Object subclass:#Controller
instanceVariableNames:'model view sensor'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
!
Controller comment:'
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
Controllers can be used to controll the user-interactions
to a Model which is shown in a view. For very simple views,
(and due to the evolution of Smalltalk/X) many view-classes have
the controller function integrated.
Instance variables:
view aView the view I controll
model aModel the model which is to be worked on
$Header: /cvs/stx/stx/libview/Controller.st,v 1.2 1993-10-13 00:44:50 claus Exp $
written summer 92 by claus
'!
!Controller methodsFor:'initialize / release'!
initialize
"initialize the controller; subclasses should redefine
this and include a super initialize for proper initialization."
^ self
!
release
view controller:nil.
view := nil.
model := nil
! !
!Controller methodsFor:'accessing'!
view:aView
"set my view"
view notNil ifTrue:[
model notNil ifTrue:[
model removeDependent:view
]
].
view := aView.
model notNil ifTrue:[
model addDependent:view
].
sensor := WindowSensor new.
sensor view:view
!
view
"return my view"
^ view
!
model:aModel
"set my model"
model notNil ifTrue:[
model removeDependent:view "self"
].
model := aModel.
model notNil ifTrue:[model addDependent:view]
!
model
"return my model"
^ view model
!
sensor:aSensor
sensor := aSensor
!
sensor
"return my sensor"
^ sensor
! !
!Controller methodsFor:'event processing'!
process
|damage event type|
[sensor hasDamage] whileTrue:[
damage := sensor nextDamage.
'controller processing expose' printNewline.
view exposeX:damage left y:damage top
width:damage width height:damage height.
].
[sensor hasEvents] whileTrue:[
'controller processing event' printNewline.
event := sensor nextEvent.
type := event at:1.
type == #buttonPress ifTrue:[
view buttonPress:(event at:2)
x:(event at:3)
y:(event at:4)
] ifFalse:[
type == #buttonRelease ifTrue:[
view buttonRelease:(event at:2)
x:(event at:3)
y:(event at:4)
] ifFalse:[
type == #keyPress ifTrue:[
view keyPress:(event at:2)
x:(event at:3)
y:(event at:4)
] ifFalse:[
'unknown event: ' print.
type printNewline
]
]
]
]
! !
!Controller methodsFor:'controlled view events'!
sizeChanged:how of:aView
"a views size has changed - let it handle it itself"
aView sizeChanged:how
!
created:aView
"a view has been created"
^ self
!
buttonPress:button x:x y:y in:aView
"a button event happened in aView"
aView buttonPress:button x:x y:y
!
buttonShiftPress:button x:x y:y in:aView
"a button event happened in aView"
^ self buttonPress:button x:x y:y in:aView
!
buttonMultiPress:button x:x y:y in:aView
"a button event happened in aView"
^ self buttonPress:button x:x y:y in:aView
!
buttonRelease:button x:x y:y in:aView
"a button event happened in aView"
aView buttonRelease:button x:x y:y
!
buttonMotion:state x:x y:y in:aView
"a button event happened in aView"
aView buttonMotion:state x:x y:y
!
keyPress:key x:x y:y in:aView
"a key event happened in aView"
aView keyPress:key x:x y:y
!
pointerEnter:state x:x y:y in:aView
"mouse entered view"
aView pointerEnter:state x:x y:y
!
pointerLeave:state in:aView
"mouse left view"
aView pointerLeave:state
!
focusIn:aView
"a view got keyboard"
^ self
!
focusOut:aView
"a view lost keyboard"
^ self
! !