"
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'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
!
Controller comment:'
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
$Header: /cvs/stx/stx/libview/Controller.st,v 1.14 1995-03-25 22:12:01 claus Exp $
'!
!Controller class methodsFor:'documentation'!
copyright
"
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.
"
!
version
"
$Header: /cvs/stx/stx/libview/Controller.st,v 1.14 1995-03-25 22:12:01 claus Exp $
"
!
documentation
"
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.
To allow both controller and non-controller operation, events are
sent directly to the view, if its controller instance variable
is nil. Otherwise, the controller gets the event.
For now (vsn 2.10.4) there are only a few view classes using controllers;
however, over time, more will be converted, since separating the controller
offers much more flexibility (although view initialization becomes a bit more complex).
Instance variables:
view aView the view I controll
model aModel the model which is to be worked on
"
! !
!Controller class methodsFor:'instance creation'!
new
^ self basicNew initialize
! !
!Controller methodsFor:'initialize / release'!
initialize
"initialize the controller; subclasses should redefine
this and include a super initialize for proper initialization."
^ self
!
startUp
"startup the controller; this is sent when the view realizes,
right before it becomes visible.
Can be redefined in subclasses to do some startup action."
^ self
!
release
"close down the controller; this is sent when the view is destroyed.
Can be redefined in subclasses to do some cleanup action. However,
these redfined methods should do a super release."
view controller:nil.
view := nil.
model := nil
! !
!Controller methodsFor:'ST-80 compatibility'!
open
"open my view"
view open
! !
!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
].
!
view
"return my view"
^ view
!
model:aModel
"set my model"
model notNil ifTrue:[
model removeDependent:view
].
model := aModel.
model notNil ifTrue:[model addDependent:view]
!
model
"return my model"
^ view model
!
menuHolder
^ nil
! !
!Controller methodsFor:'event handling'!
redButtonActivity
"actually, this should be called 'leftButtonActivity'.
But for ST-80 compatibility ...."
^ self
!
yellowButtonActivity
"actually, this should be called 'middleButtonActivity'.
But for ST-80 compatibility ...."
|sym menu actionSelector menuHolder|
(menuHolder := self menuHolder) notNil ifTrue:[
self halt.
].
"
try ST-80 style menus first:
if there is a model, and a menuSymbol is defined,
ask model for the menu and launch that if non-nil.
"
(model notNil
and:[(sym := view menuSymbol) notNil
and:[sym isSymbol]]) ifTrue:[
"
ask model for the menu
"
menu := model perform:sym.
menu notNil ifTrue:[
"
got one, launch the menu. It is supposed
to return an actionSelector.
"
actionSelector := menu startUp.
(actionSelector notNil
and:[actionSelector isSymbol]) ifTrue:[
model perform:actionSelector
]
].
^ self
].
(menu := view middleButtonMenu) notNil ifTrue:[
menu showAtPointer
]
!
blueButtonActivity
"actually, this should be called 'rightButtonActivity'.
But for ST-80 compatibility ...."
^ self
! !
!Controller methodsFor:'low level events'!
buttonPress:button x:x y:y
"a mouse button was pressed in my view.
Translate buttonPress events into similar ST-80 type
event messages. This method and/or these ST-80 methods
can be redefined in subclasses"
((button == 1) or:[button == #select]) ifTrue:[
self redButtonActivity
].
((button == 2) or:[button == #menu]) ifTrue:[
self yellowButtonActivity
].
(button == 3) ifTrue:[
self blueButtonActivity
]
!
buttonMultiPress:button x:x y:y
"a mouse button was pressed again shortly after in my view"
^ self buttonPress:button x:x y:y
!
buttonShiftPress:button x:x y:y
"a mouse button was pressed again shortly after in my view"
^ self buttonPress:button x:x y:y
!
buttonRelease:button x:x y:y
"a mouse button was released in my view; nothing done here"
^ self
!
buttonMotion:buttonMask x:x y:y
"mouse was moved with button pressed in my view; nothing done here"
^ self
!
pointerEnter:state x:x y:y
"mouse pointer entered my view; nothing done here"
^ self
!
pointerLeave:state
"mouse pointer left my view; nothing done here"
^ self
!
focusIn
"my view got the keyboard focus; nothing done here"
^ self
!
focusOut
"my view lost keyboard focus; nothing done here"
^ self
!
keyPress:key x:x y:y
"key was pressed in my view; nothing done here"
^ self
!
keyRelease:key x:x y:y
"key was released in my view; nothing done here"
^ self
! !