Controller.st
changeset 245 86a1f74b2306
parent 222 f46120c95d87
child 252 87bbc0f751d7
--- a/Controller.st	Thu Nov 23 11:38:43 1995 +0100
+++ b/Controller.st	Thu Nov 23 11:39:48 1995 +0100
@@ -11,10 +11,10 @@
 "
 
 Object subclass:#Controller
-       instanceVariableNames:'model view sensor'
-       classVariableNames:''
-       poolDictionaries:''
-       category:'Interface-Support-Controllers'
+	 instanceVariableNames:'model view sensor'
+	 classVariableNames:''
+	 poolDictionaries:''
+	 category:'Interface-Support-Controllers'
 !
 
 !Controller class methodsFor:'documentation'!
@@ -33,10 +33,6 @@
 "
 !
 
-version
-    ^ '$Header: /cvs/stx/stx/libview/Controller.st,v 1.25 1995-11-14 18:13:53 cg Exp $'
-!
-
 documentation
 "
     Controllers can be used to controll the user-interactions
@@ -55,6 +51,10 @@
 	view        aView               the view I controll
 	model       aModel              the model which is to be worked on
 "
+!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview/Controller.st,v 1.26 1995-11-23 10:39:48 cg Exp $'
 ! !
 
 !Controller class methodsFor:'instance creation'!
@@ -63,37 +63,6 @@
     ^ 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 controlInitialize.
-!
-
-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 redefined methods should do a super release."
-
-    view notNil ifTrue:[view controller:nil].
-    view := nil.
-    model := nil
-!
-
-controlInitialize
-    ^ self
-! !
-
 !Controller methodsFor:'ST-80 compatibility'!
 
 open
@@ -104,6 +73,48 @@
 
 !Controller methodsFor:'accessing'!
 
+menuHolder 
+    "by default, the model has to provide the menu"
+
+    model isNil ifTrue:[^ view].
+    ^ model
+!
+
+menuPerformer 
+    "by default, the model is performing menu actions"
+
+    model isNil ifTrue:[^ view].
+    ^ model
+!
+
+model
+    "return my model"
+
+    ^ model
+!
+
+model:aModel
+    "set my model"
+
+    model notNil ifTrue:[
+	model removeDependent:view
+    ].
+    model := aModel.
+"/    model notNil ifTrue:[model addDependent:view]
+!
+
+sensor 
+    "return my views sensor"
+
+    ^ view sensor
+!
+
+view
+    "return my view"
+
+    ^ view
+!
+
 view:aView
     "set my view"
 
@@ -119,86 +130,17 @@
 	    view model:model
 	]
     ].
-!
-
-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"
-
-    ^ model
-!
-
-sensor 
-    "return my views sensor"
-
-    ^ view sensor
-!
-
-menuHolder 
-    "by default, the model has to provide the menu"
-
-    model isNil ifTrue:[^ view].
-    ^ model
-!
-
-menuPerformer 
-    "by default, the model is performing menu actions"
-
-    model isNil ifTrue:[^ view].
-    ^ model
-! !
-
-!Controller methodsFor:'menus'!
-
-yellowButtonMenu
-    "actually, this should be called 'middleButtonMenu'.
-     But for ST-80 compatibility ...."
-
-    |sym menuHolder m|
-
-"/    (m := view middleButtonMenu) notNil ifTrue:[
-"/        "/
-"/        "/ has been assigned a static middleButtonMenu
-"/        "/ (or a cached menu)
-"/        "/
-"/        ^ m
-"/    ].
-
-    menuHolder := self menuHolder.
-
-    "
-     try ST-80 style menus first:
-     if there is a model, and a menuMessage is defined,
-     ask model for the menu and launch that if non-nil.
-    "
-    (menuHolder notNil 
-    and:[(sym := view menuMessage) notNil
-    and:[sym isSymbol]]) ifTrue:[
-	"
-	 ask model for the menu
-	"
-	^ menuHolder perform:sym.
-    ].
-    ^ nil
 ! !
 
 !Controller methodsFor:'event handling'!
 
+blueButtonActivity
+    "actually, this should be called 'rightButtonActivity'.
+     But for ST-80 compatibility ...."
+
+    ^ self
+!
+
 redButtonActivity
     "actually, this should be called 'leftButtonActivity'.
      But for ST-80 compatibility ...."
@@ -247,17 +189,53 @@
     (menu := view middleButtonMenu) notNil ifTrue:[
 	menu showAtPointer
     ]
+! !
+
+!Controller methodsFor:'initialize / release'!
+
+controlInitialize
+    ^ self
+!
+
+initialize
+    "initialize the controller; subclasses should redefine
+     this and include a super initialize for proper initialization."
+
+    ^ self
 !
 
-blueButtonActivity
-    "actually, this should be called 'rightButtonActivity'.
-     But for ST-80 compatibility ...."
+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 redefined methods should do a super release."
 
-    ^ self
+    view notNil ifTrue:[view controller:nil].
+    view := nil.
+    model := nil
+!
+
+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 controlInitialize.
 ! !
 
 !Controller methodsFor:'low level events'!
 
+buttonMotion:buttonMask x:x y:y
+    "mouse was moved with button pressed in my view; nothing done here"
+
+    ^ self
+!
+
+buttonMultiPress:button x:x y:y
+    "a mouse button was pressed again shortly after in my view"
+
+    ^ self buttonPress:button x:x y:y
+!
+
 buttonPress:button x:x y:y
     "a mouse button was pressed in my view.
      Translate buttonPress events into similar ST-80 type
@@ -275,10 +253,10 @@
     ]
 !
 
-buttonMultiPress:button x:x y:y
-    "a mouse button was pressed again shortly after in my view"
+buttonRelease:button x:x y:y
+    "a mouse button was released in my view; nothing done here"
 
-    ^ self buttonPress:button x:x y:y
+    ^ self
 !
 
 buttonShiftPress:button x:x y:y
@@ -287,59 +265,11 @@
     ^ 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
-!
-
-devicePointerEnter:state x:x y:y
+deviceButtonMotion:state x:x y:y
     "this is the low-level (untransformed) event as received
      from the device (i.e. coordinates are in device coordinates). 
      If there is a transformation, apply the inverse
-     and send a pointerEnter with the logical coordinates."
+     and send a buttonMotion with the logical coordinates."
 
     |lx ly trans|
 
@@ -349,7 +279,41 @@
 	lx := trans applyInverseToX:lx.
 	ly := trans applyInverseToY:ly.
     ].
-    self pointerEnter:state x:lx y:ly
+    self buttonMotion:state x:lx y:ly
+!
+
+deviceButtonPress:button x:x y:y
+    "this is the low-level (untransformed) event as received
+     from the device (i.e. coordinates are in device coordinates). 
+     If there is a transformation, apply the inverse
+     and send a buttonPress with the logical coordinates."
+
+    |lx ly trans|
+
+    lx := x.
+    ly := y.
+    (trans := view transformation) notNil ifTrue:[
+	lx := trans applyInverseToX:lx.
+	ly := trans applyInverseToY:ly.
+    ].
+    self buttonPress:button x:lx y:ly
+!
+
+deviceButtonRelease:button x:x y:y
+    "this is the low-level (untransformed) event as received
+     from the device (i.e. coordinates are in device coordinates). 
+     If there is a transformation, apply the inverse
+     and send a buttonRelease with the logical coordinates."
+
+    |lx ly trans|
+
+    lx := x.
+    ly := y.
+    (trans := view transformation) notNil ifTrue:[
+	lx := trans applyInverseToX:lx.
+	ly := trans applyInverseToY:ly.
+    ].
+    self buttonRelease:button x:lx y:ly
 !
 
 deviceKeyPress:key x:x y:y
@@ -386,11 +350,11 @@
     self keyRelease:key x:lx y:ly
 !
 
-deviceButtonPress:button x:x y:y
+devicePointerEnter:state x:x y:y
     "this is the low-level (untransformed) event as received
      from the device (i.e. coordinates are in device coordinates). 
      If there is a transformation, apply the inverse
-     and send a buttonPress with the logical coordinates."
+     and send a pointerEnter with the logical coordinates."
 
     |lx ly trans|
 
@@ -400,39 +364,76 @@
 	lx := trans applyInverseToX:lx.
 	ly := trans applyInverseToY:ly.
     ].
-    self buttonPress:button x:lx y:ly
+    self pointerEnter:state x:lx y:ly
+!
+
+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
+!
+
+pointerEnter:state x:x y:y
+    "mouse pointer entered my view; nothing done here"
+
+    ^ self
 !
 
-deviceButtonRelease:button x:x y:y
-    "this is the low-level (untransformed) event as received
-     from the device (i.e. coordinates are in device coordinates). 
-     If there is a transformation, apply the inverse
-     and send a buttonRelease with the logical coordinates."
+pointerLeave:state
+    "mouse pointer left my view; nothing done here"
 
-    |lx ly trans|
+    ^ self
+! !
 
-    lx := x.
-    ly := y.
-    (trans := view transformation) notNil ifTrue:[
-	lx := trans applyInverseToX:lx.
-	ly := trans applyInverseToY:ly.
-    ].
-    self buttonRelease:button x:lx y:ly
-!
+!Controller methodsFor:'menus'!
+
+yellowButtonMenu
+    "actually, this should be called 'middleButtonMenu'.
+     But for ST-80 compatibility ...."
+
+    |sym menuHolder m|
 
-deviceButtonMotion:state x:x y:y
-    "this is the low-level (untransformed) event as received
-     from the device (i.e. coordinates are in device coordinates). 
-     If there is a transformation, apply the inverse
-     and send a buttonMotion with the logical coordinates."
+"/    (m := view middleButtonMenu) notNil ifTrue:[
+"/        "/
+"/        "/ has been assigned a static middleButtonMenu
+"/        "/ (or a cached menu)
+"/        "/
+"/        ^ m
+"/    ].
 
-    |lx ly trans|
+    menuHolder := self menuHolder.
 
-    lx := x.
-    ly := y.
-    (trans := view transformation) notNil ifTrue:[
-	lx := trans applyInverseToX:lx.
-	ly := trans applyInverseToY:ly.
+    "
+     try ST-80 style menus first:
+     if there is a model, and a menuMessage is defined,
+     ask model for the menu and launch that if non-nil.
+    "
+    (menuHolder notNil 
+    and:[(sym := view menuMessage) notNil
+    and:[sym isSymbol]]) ifTrue:[
+	"
+	 ask model for the menu
+	"
+	^ menuHolder perform:sym.
     ].
-    self buttonMotion:state x:lx y:ly
+    ^ nil
 ! !
+