'From Squeak 2.4b of April 23, 1999 on 4 August 1999 at 2:12:06 am'! "Change Set: MenuLocationFix-dew Date: 4 August 1999 Author: Doug Way Adjusts the location of pop-up menus when the mouse is near the right side of the screen, so that the pop-up menu appears just to the left of the mouse. This prevents the mouse from appearing on top of the menu and accidentally selecting an item. (For both Morphic and MVC.)"! !MenuMorph methodsFor: 'control' stamp: 'dew 8/4/1999 00:15'! popUpAt: aPoint forHand: hand "Present this menu at the given point under control of the given hand." | selectedItem i yOffset sub delta | popUpOwner _ hand. originalEvent _ hand lastEvent. selectedItem _ self items detect: [:each | each == lastSelection] ifNone: [self items isEmpty ifTrue: [^ self] ifFalse: [self items first]]. "Note: items may not be laid out yet (I found them all to be at 0@0), so have to add up heights of items above the selected item." i _ 0. yOffset _ 0. [(sub _ self submorphs at: (i _ i + 1)) == selectedItem] whileFalse: [yOffset _ yOffset + sub height]. self position: aPoint - (2 @ (yOffset + 8)). self bounds right > hand worldBounds right ifTrue: [self position: self position - (self bounds width - 4 @ 0)]. delta _ self bounds amountToTranslateWithin: hand worldBounds. delta = (0 @ 0) ifFalse: [self position: self position + delta]. hand world addMorphFront: self. hand newMouseFocus: selectedItem. self changed! ! !PopUpMenu methodsFor: 'displaying' stamp: 'dew 8/4/1999 01:49'! displayAt: aPoint withCaption: captionOrNil during: aBlock "Display the receiver just to the right of aPoint while aBlock is evaluated. If the receiver is forced off screen, display it just to the right." | delta savedArea captionForm captionSave outerFrame captionText tFrame frameSaveLoc captionBox | marker ifNil: [self computeForm]. frame _ frame align: marker leftCenter with: aPoint + (2@0). outerFrame _ frame. captionOrNil notNil ifTrue: [captionText _ (DisplayText text: captionOrNil asText textStyle: TextStyle default copy centered) foregroundColor: Color black backgroundColor: Color white. tFrame _ captionText boundingBox insetBy: -2. outerFrame _ frame merge: (tFrame align: tFrame bottomCenter with: frame topCenter + (0@2))]. delta _ outerFrame amountToTranslateWithin: Display boundingBox. frame right > Display boundingBox right ifTrue: [delta _ 0 - frame width @ delta y]. frame _ frame translateBy: delta. captionOrNil notNil ifTrue: [captionForm _ captionText form. captionBox _ captionForm boundingBox expandBy: 4. captionBox _ captionBox align: captionBox bottomCenter with: frame topCenter + (0@2). captionSave _ Form fromDisplay: captionBox. Display border: captionBox width: 4 fillColor: Color white. Display border: captionBox width: 2 fillColor: Color black. captionForm displayAt: captionBox topLeft + 4]. marker _ marker align: marker leftCenter with: aPoint + delta + (2@0). savedArea _ Form fromDisplay: frame. self menuForm displayOn: Display at: (frameSaveLoc _ frame topLeft). selection ~= 0 ifTrue: [Display reverse: marker]. Cursor normal showWhile: [aBlock value]. savedArea displayOn: Display at: frameSaveLoc. captionOrNil notNil ifTrue: [captionSave displayOn: Display at: captionBox topLeft]! !