'From Squeak3.3alpha of 18 January 2002 [latest update: #4850] on 1 May 2002 at 1:50:53 am'! "Change Set: menuFixes-sw Date: 1 May 2002 Author: Scott Wallace Fixes for three menu bugs, the first two of which were reported by Ken Causey. (1) A mouse-click on open desktop within 14 pixels of the bottom of the screen would pop up the world menu but then immediately dismiss it; this bug had arrived in update 4598OccamsMenuKeys-hg-di, in December 2001. (2) A mouse-click that brought up a menu, when initiated near the right edge of the screen, would often result in the unexpected and unwanted choosing and execution of a menu item, rather than simply leaving the menu up adjacent to the cursor; the cause was that the positioning was figured out before self-updating items in the menu had been given a chance to get updated. This was a paricularly nasty bug because if you clicked on the desktop near the right edge of the screen, you might get a completely unintended snapshot taken, etc. This bug, incidentalliy, dates back to the event reworking of autumn 2000. (3) The menu title for the halo menu of a flap tap was still appearing in the window-title font."! !MenuMorph methodsFor: 'construction' stamp: 'sw 5/1/2002 00:29'! addTitle: aString updatingSelector: aSelector updateTarget: aTarget "Add a title line at the top of this menu Make aString its initial contents. If aSelector is not nil, then periodically obtain fresh values for its contents by sending aSelector to aTarget.." | title | title _ AlignmentMorph new. self setTitleParametersFor: title. title vResizing: #shrinkWrap. title listDirection: #topToBottom. title wrapCentering: #center; cellPositioning: #topCenter; borderWidth: 0; layoutInset: 0. aSelector ifNil: [(aString asString findTokens: String cr) do: [:line | title addMorphBack: (StringMorph new contents: line; font: Preferences standardMenuFont)]] ifNotNil: [title addMorphBack: (UpdatingStringMorph new lock; font: Preferences standardMenuFont; useStringFormat; target: aTarget; getSelector: aSelector)]. title setProperty: #titleString toValue: aString. self addMorphFront: title. (self hasProperty: #needsTitlebarWidgets) ifTrue: [self addStayUpIcons]! ! !MenuMorph methodsFor: 'control' stamp: 'sw 5/1/2002 01:35'! popUpAt: aPoint forHand: hand in: aWorld allowKeyboard: aBoolean "Present this menu at the given point under control of the given hand." | evt | self items isEmpty ifTrue: [^ self]. aWorld addMorphFront: self; startSteppingSubmorphsOf: self. self positionAt: aPoint relativeTo: (selectedItem ifNil: [self items first]) inWorld: aWorld. "Acquire focus for valid pop up behavior" hand newMouseFocus: self. aBoolean ifTrue: [hand newKeyboardFocus: self]. evt _ hand lastEvent. (evt isKeyboard or: [evt isMouse and: [evt anyButtonPressed not]]) ifTrue: ["Select first item if button not down" self moveSelectionDown: 1 event: evt]. self changed! ! !MenuMorph methodsFor: 'private' stamp: 'sw 5/1/2002 01:39'! positionAt: aPoint relativeTo: aMenuItem inWorld: aWorld "Note: items may not be laid out yet (I found them all to be at 0@0), so we have to add up heights of items above the selected item." | i yOffset sub delta | self fullBounds. "force layout" i _ 0. yOffset _ 0. [(sub _ self submorphs at: (i _ i + 1)) == aMenuItem] whileFalse: [yOffset _ yOffset + sub height]. self position: aPoint - (2 @ (yOffset + 8)). "If it doesn't fit, show it to the left, not to the right of the hand." self right > aWorld worldBounds right ifTrue: [self right: aPoint x + 1]. "Make sure that the menu fits in the world." delta _ self bounds amountToTranslateWithin: (aWorld worldBounds withHeight: ((aWorld worldBounds height - 18) max: (ActiveHand position y) + 1)). delta = (0 @ 0) ifFalse: [self position: self position + delta]! !