diff -r 28815246bbc1 -r 450ce95a72a4 PullDownMenu.st --- a/PullDownMenu.st Tue Aug 30 00:54:47 1994 +0200 +++ b/PullDownMenu.st Mon Oct 10 04:03:47 1994 +0100 @@ -1,6 +1,6 @@ " COPYRIGHT (c) 1989 by Claus Gittinger - All Rights Reserved + 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 @@ -12,20 +12,27 @@ View subclass:#PullDownMenu instanceVariableNames:'menus titles activeMenuNumber - showSeparatingLines topMargin - fgColor bgColor activeFgColor activeBgColor - onLevel offLevel - keepMenu' - classVariableNames:'' + showSeparatingLines topMargin + fgColor bgColor activeFgColor activeBgColor + onLevel offLevel + keepMenu' + classVariableNames:'DefaultFont + DefaultViewBackground + DefaultForegroundColor + DefaultBackgroundColor + DefaultHilightForegroundColor + DefaultHilightBackgroundColor + DefaultLevel DefaultHilightLevel + DefaultShadowColor DefaultLightColor' poolDictionaries:'' category:'Views-Menus' ! PullDownMenu comment:' COPYRIGHT (c) 1989 by Claus Gittinger - All Rights Reserved + All Rights Reserved -$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.5 1994-08-07 13:23:11 claus Exp $ +$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.6 1994-10-10 03:02:41 claus Exp $ '! !PullDownMenu class methodsFor:'documentation'! @@ -33,7 +40,7 @@ copyright " COPYRIGHT (c) 1989 by Claus Gittinger - All Rights Reserved + 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 @@ -46,7 +53,7 @@ version " -$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.5 1994-08-07 13:23:11 claus Exp $ +$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.6 1994-10-10 03:02:41 claus Exp $ " ! @@ -70,10 +77,45 @@ onLevel level of entry-buttons when pressed offLevel level of entry-buttons when released keepmenu if on, pulled menu stays on click, - till clicked again (motif & windows behavior) + till clicked again (motif & windows behavior) " ! ! +!PullDownMenu class methodsFor:'defaults'! + +updateStyleCache + DefaultViewBackground := StyleSheet at:'pullDownMenuViewBackground'. + DefaultForegroundColor := StyleSheet at:'pullDownMenuForegroundColor' default:Black. + DefaultBackgroundColor := StyleSheet at:'pullDownMenuBackgroundColor'. + DefaultHilightForegroundColor := StyleSheet at:'pullDownMenuHilightForegroundColor'. + DefaultHilightBackgroundColor := StyleSheet at:'pullDownMenuHilightBackgroundColor'. + DefaultHilightLevel := StyleSheet at:'pullDownMenuHilightLevel' default:-1. + DefaultLevel := StyleSheet at:'pullDownMenuLevel' default:1. + DefaultFont := StyleSheet at:'pullDownMenuFont'. + + DefaultForegroundColor notNil ifTrue:[ + DefaultForegroundColor := DefaultForegroundColor on:Display + ]. + DefaultBackgroundColor notNil ifTrue:[ + DefaultBackgroundColor := DefaultBackgroundColor on:Display + ]. + DefaultShadowColor notNil ifTrue:[ + DefaultShadowColor := DefaultShadowColor on:Display + ]. + DefaultLightColor notNil ifTrue:[ + DefaultLightColor := DefaultLightColor on:Display + ]. + DefaultHilightForegroundColor notNil ifTrue:[ + DefaultHilightForegroundColor := DefaultHilightForegroundColor on:Display + ]. + DefaultHilightBackgroundColor notNil ifTrue:[ + DefaultHilightBackgroundColor := DefaultHilightBackgroundColor on:Display + ]. + DefaultFont notNil ifTrue:[ + DefaultFont := DefaultFont on:Display + ]. +! ! + !PullDownMenu class methodsFor:'instance creation'! labels:titleArray @@ -89,43 +131,74 @@ font := font on:device. self origin:(0.0 @ 0.0) - extent:(1.0 @ (font height + (font descent * 2) + topMargin)). + extent:(1.0 @ (font height + (font descent * 2) + topMargin)). ! initStyle super initStyle. showSeparatingLines := false. - fgColor := Black. - bgColor := viewBackground. - onLevel := -1. - offLevel := 1. + DefaultViewBackground notNil ifTrue:[ + viewBackground := DefaultViewBackground + ]. + + DefaultForegroundColor notNil ifTrue:[ + fgColor := DefaultForegroundColor + ] ifFalse:[ + fgColor := Black. + ]. + DefaultBackgroundColor notNil ifTrue:[ + bgColor := DefaultBackgroundColor + ] ifFalse:[ + bgColor := viewBackground. + ]. + onLevel := DefaultHilightLevel. + offLevel := DefaultLevel. self is3D ifTrue:[ - device hasColors ifTrue:[ - activeFgColor := Color name:'yellow' - ] ifFalse:[ - activeFgColor := White - ]. - device hasGreyscales ifTrue:[ - activeBgColor := bgColor. - ] ifFalse:[ - activeBgColor := fgColor. - ]. - topMargin := 2. + device hasColors ifTrue:[ + activeFgColor := Color name:'yellow' + ] ifFalse:[ + activeFgColor := White + ]. + device hasGreyscales ifTrue:[ + activeBgColor := bgColor. + ] ifFalse:[ + activeBgColor := fgColor. + ]. + topMargin := 2. - ((style == #iris) or:[style == #motif]) ifTrue:[ - self level:2. - softEdge := true. - onLevel := 2. - offLevel := 0. - activeFgColor := fgColor - ] + ((style == #iris) or:[style == #motif]) ifTrue:[ + self level:2. + softEdge := true. + onLevel := 2. + offLevel := 0. + activeFgColor := fgColor + ] ] ifFalse:[ - activeFgColor := bgColor. - activeBgColor := fgColor. - topMargin := 0 + activeFgColor := bgColor. + activeBgColor := fgColor. + topMargin := 0 + ]. + + DefaultHilightForegroundColor notNil ifTrue:[ + activeFgColor := DefaultHilightForegroundColor + ]. + DefaultHilightBackgroundColor notNil ifTrue:[ + activeBgColor := DefaultHilightBackgroundColor ]. + DefaultShadowColor notNil ifTrue:[ + shadowColor := DefaultShadowColor on:device + ]. + DefaultLightColor notNil ifTrue:[ + lightColor := DefaultLightColor on:device + ]. + + bgColor := bgColor on:device. + fgColor := fgColor on:device. + activeBgColor := activeBgColor on:device. + activeFgColor := activeFgColor on:device. + keepMenu := (style == #motif) or:[(style == #iris) or:[style == #mswindows]]. ! @@ -151,7 +224,7 @@ showSeparatingLines := aBoolean. shown ifTrue:[ - self redraw + self redraw ] ! @@ -171,11 +244,11 @@ menus := Array new:numberOfLabels. titles := Array new:numberOfLabels. 1 to:numberOfLabels do:[:index | - titles at:index put:(titleArray at:index) printString + titles at:index put:(titleArray at:index) printString ]. shown ifTrue:[ - self clear. - self redraw + self clear. + self redraw ] ! @@ -211,8 +284,8 @@ index := self indexOf:aString. (index == 0) ifTrue:[^ nil]. aMenu origin:((left + (self titleLenUpTo:index)) - @ - (height + aMenu borderWidth)). + @ + (height + aMenu borderWidth)). aMenu hidden:true. menus at:index put:aMenu ! @@ -223,10 +296,10 @@ |menuView| menuView := MenuView labels:labels - selectors:selectors - args:args - receiver:anObject - for:self. + selectors:selectors + args:args + receiver:anObject + for:self. self at:aString putMenu:menuView ! @@ -236,10 +309,10 @@ |menuView| menuView := MenuView labels:labels - selector:selector - args:args - receiver:anObject - for:self. + selector:selector + args:args + receiver:anObject + for:self. self at:aString putMenu:menuView ! @@ -249,9 +322,9 @@ |menuView| menuView := MenuView labels:labels - selectors:selectors - receiver:anObject - for:self. + selectors:selectors + receiver:anObject + for:self. self at:aString putMenu:menuView ! ! @@ -265,14 +338,14 @@ (index <= 1) ifTrue:[^ 0]. len := 0. titles from:1 to:(index - 1) do:[:string | - len := len + (font widthOf:(' ' , string , ' ')). - showSeparatingLines ifTrue:[ - self is3D ifTrue:[ - len := len + 2 - ] ifFalse:[ - len := len + 1 - ] - ] + len := len + (font widthOf:(' ' , string , ' ')). + showSeparatingLines ifTrue:[ + self is3D ifTrue:[ + len := len + 2 + ] ifFalse:[ + len := len + 1 + ] + ] ]. ^ len ! @@ -281,7 +354,7 @@ "return the index of the menu with title; return 0 if not found" (stringOrNumber isMemberOf:SmallInteger) ifTrue:[ - ^ stringOrNumber + ^ stringOrNumber ]. ^ titles indexOf:stringOrNumber ! @@ -292,15 +365,15 @@ |index| (font device == device) ifTrue:[ - index := 1. - menus do:[:aMenu | - aMenu notNil ifTrue:[ - aMenu origin:((left + (self titleLenUpTo:index)) - @ - (height + aMenu borderWidth)) - ]. - index := index + 1 - ] + index := 1. + menus do:[:aMenu | + aMenu notNil ifTrue:[ + aMenu origin:((left + (self titleLenUpTo:index)) + @ + (height + aMenu borderWidth)) + ]. + index := index + 1 + ] ] ! ! @@ -312,22 +385,22 @@ yText := ((height - (font height)) // 2) + (font ascent) "+ topMargin". w := font widthOf:string. selected ifTrue:[ - self paint:activeBgColor + self paint:activeBgColor ] ifFalse:[ - self paint:bgColor + self paint:bgColor ]. self fillRectangleX:x y:0 width:w height:height. self is3D ifTrue:[ - self drawEdgesForX:x y:0 - width:w - height:height - level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) + self drawEdgesForX:x y:0 + width:w + height:height + level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) ]. selected ifTrue:[ - self paint:activeFgColor + self paint:activeFgColor ] ifFalse:[ - self paint:fgColor + self paint:fgColor ]. self displayString:string x:x y:yText ! @@ -335,27 +408,27 @@ highlightActiveTitle |x string| activeMenuNumber notNil ifTrue:[ - x := self titleLenUpTo:activeMenuNumber. - string := ' ' , (titles at:activeMenuNumber) , ' '. - self drawTitle:string x:x selected:true + x := self titleLenUpTo:activeMenuNumber. + string := ' ' , (titles at:activeMenuNumber) , ' '. + self drawTitle:string x:x selected:true ] ! unHighlightActiveTitle |x string| activeMenuNumber notNil ifTrue:[ - x := self titleLenUpTo:activeMenuNumber. - string := ' ' , (titles at:activeMenuNumber) , ' '. - self drawTitle:string x:x selected:false + x := self titleLenUpTo:activeMenuNumber. + string := ' ' , (titles at:activeMenuNumber) , ' '. + self drawTitle:string x:x selected:false ] ! hideActiveMenuRelease:aBoolean activeMenuNumber notNil ifTrue:[ - (menus at:activeMenuNumber) unrealize. - self unHighlightActiveTitle. - aBoolean ifTrue:[device ungrabPointer. self cursor:Cursor normal]. - activeMenuNumber := nil + (menus at:activeMenuNumber) unrealize. + self unHighlightActiveTitle. + aBoolean ifTrue:[device ungrabPointer. self cursor:Cursor normal]. + activeMenuNumber := nil ] ! @@ -371,12 +444,12 @@ activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false]. subMenu := menus at:aNumber. subMenu notNil ifTrue:[ - activeMenuNumber := aNumber. - self highlightActiveTitle. - subMenu deselect. - subMenu create. - subMenu saveUnder:true. - subMenu raise show + activeMenuNumber := aNumber. + self highlightActiveTitle. + subMenu deselect. + subMenu create. + subMenu saveUnder:true. + subMenu raise show ] ! ! @@ -394,23 +467,23 @@ y := height "- 1". index := 0. titles do:[:title | - string := ' ' , title , ' '. - self drawTitle:string x:x selected:(index == activeMenuNumber). - x := x + (font widthOf:string). - showSeparatingLines ifTrue:[ - self is3D ifTrue:[ - self paint:shadowColor. - self displayLineFromX:x y:0 toX:x y:y. - x := x + 1. - self paint:lightColor. - self displayLineFromX:x y:0 toX:x y:y - ] ifFalse:[ - self paint:fgColor. - self displayLineFromX:x y:0 toX:x y:y - ]. - x := x + 1 - ]. - index := index + 1 + string := ' ' , title , ' '. + self drawTitle:string x:x selected:(index == activeMenuNumber). + x := x + (font widthOf:string). + showSeparatingLines ifTrue:[ + self is3D ifTrue:[ + self paint:shadowColor. + self displayLineFromX:x y:0 toX:x y:y. + x := x + 1. + self paint:lightColor. + self displayLineFromX:x y:0 toX:x y:y + ] ifFalse:[ + self paint:fgColor. + self displayLineFromX:x y:0 toX:x y:y + ]. + x := x + 1 + ]. + index := index + 1 ] ! @@ -423,17 +496,17 @@ xstart := 0. 1 to:(titles size) do:[:index | - string := ' ' , (titles at:index) , ' '. - xend := xstart + (font widthOf:string). - showSeparatingLines ifTrue:[ - self is3D ifTrue:[ - xend := xend + 2 - ] ifFalse:[ - xend := xend + 1 - ] - ]. - (x between:xstart and:xend) ifTrue:[^ index]. - xstart := xend + string := ' ' , (titles at:index) , ' '. + xend := xstart + (font widthOf:string). + showSeparatingLines ifTrue:[ + self is3D ifTrue:[ + xend := xend + 2 + ] ifFalse:[ + xend := xend + 1 + ] + ]. + (x between:xstart and:xend) ifTrue:[^ index]. + xstart := xend ]. ^ nil ! @@ -442,40 +515,40 @@ |titleIndex activeMenu activeLeft activeTop| (y between:0 and:height) ifTrue:[ - titleIndex := self titleIndexForX:x. + titleIndex := self titleIndexForX:x. ]. " now, titleIndex is non-nil if pressed within myself " (titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[ - self pullMenu:titleIndex. - keepMenu ifTrue:[ - device grabPointerIn:self id. - self cursor:Cursor upRightArrow - ] + self pullMenu:titleIndex. + keepMenu ifTrue:[ + device grabPointerIn:self id. + self cursor:Cursor upRightArrow + ] ] ifFalse:[ - keepMenu ifTrue:[ - titleIndex == activeMenuNumber ifTrue:[ - "same pressed again ... stay" - ^ self - ]. - "moving around below" - activeMenuNumber isNil ifTrue:[^self]. - activeMenu := menus at:activeMenuNumber. - activeLeft := activeMenu left. - (x between:activeLeft and:(activeMenu right)) ifTrue:[ - activeTop := activeMenu top. - (y between:activeTop and:(activeMenu bottom)) ifTrue:[ - "moving around in menu" - activeMenu buttonPress:button - x:(x - activeLeft) - y:(y - activeTop). - ^ self - ] - ]. - ]. - self hideActiveMenu + keepMenu ifTrue:[ + titleIndex == activeMenuNumber ifTrue:[ + "same pressed again ... stay" + ^ self + ]. + "moving around below" + activeMenuNumber isNil ifTrue:[^self]. + activeMenu := menus at:activeMenuNumber. + activeLeft := activeMenu left. + (x between:activeLeft and:(activeMenu right)) ifTrue:[ + activeTop := activeMenu top. + (y between:activeTop and:(activeMenu bottom)) ifTrue:[ + "moving around in menu" + activeMenu buttonPress:button + x:(x - activeLeft) + y:(y - activeTop). + ^ self + ] + ]. + ]. + self hideActiveMenu ] ! @@ -483,33 +556,33 @@ |titleIndex activeMenu activeLeft activeTop| (y < height) ifTrue:[ - "moving around in title line" - activeMenuNumber notNil ifTrue:[ - (menus at:activeMenuNumber) selection:nil - ]. - titleIndex := self titleIndexForX:x. - titleIndex notNil ifTrue:[ - (titleIndex ~~ activeMenuNumber) ifTrue:[ - self pullMenu:titleIndex - ] - ] + "moving around in title line" + activeMenuNumber notNil ifTrue:[ + (menus at:activeMenuNumber) selection:nil + ]. + titleIndex := self titleIndexForX:x. + titleIndex notNil ifTrue:[ + (titleIndex ~~ activeMenuNumber) ifTrue:[ + self pullMenu:titleIndex + ] + ] ] ifFalse:[ - "moving around below" - activeMenuNumber isNil ifTrue:[^self]. - activeMenu := menus at:activeMenuNumber. - activeLeft := activeMenu left. - (x between:activeLeft and:(activeMenu right)) ifTrue:[ - activeTop := activeMenu top. - (y between:activeTop and:(activeMenu bottom)) ifTrue:[ - "moving around in menu" - activeMenu buttonMotion:button - x:(x - activeLeft) - y:(y - activeTop). - ^ self - ] - ]. - "moved outside menu" - activeMenu selection:nil + "moving around below" + activeMenuNumber isNil ifTrue:[^self]. + activeMenu := menus at:activeMenuNumber. + activeLeft := activeMenu left. + (x between:activeLeft and:(activeMenu right)) ifTrue:[ + activeTop := activeMenu top. + (y between:activeTop and:(activeMenu bottom)) ifTrue:[ + "moving around in menu" + activeMenu buttonMotion:button + x:(x - activeLeft) + y:(y - activeTop). + ^ self + ] + ]. + "moved outside menu" + activeMenu selection:nil ] ! @@ -518,33 +591,33 @@ hideMenu := false. (y >= height) ifTrue:[ - "release below title-line" - activeMenuNumber isNil ifTrue:[^self]. - activeMenu := menus at:activeMenuNumber. - activeLeft := activeMenu left. - " - released in a submenu ? - " - (x between:activeLeft and:(activeMenu right)) ifTrue:[ - activeTop := activeMenu top. - (y between:activeTop and:(activeMenu bottom)) ifTrue:[ - "release in menu" - self hideActiveMenu. - activeMenu buttonRelease:button - x:(x - activeLeft) - y:(y - activeTop). - ^ self - ] - ]. - hideMenu := true. + "release below title-line" + activeMenuNumber isNil ifTrue:[^self]. + activeMenu := menus at:activeMenuNumber. + activeLeft := activeMenu left. + " + released in a submenu ? + " + (x between:activeLeft and:(activeMenu right)) ifTrue:[ + activeTop := activeMenu top. + (y between:activeTop and:(activeMenu bottom)) ifTrue:[ + "release in menu" + self hideActiveMenu. + activeMenu buttonRelease:button + x:(x - activeLeft) + y:(y - activeTop). + ^ self + ] + ]. + hideMenu := true. ] ifFalse:[ - y < 0 ifTrue:[ - hideMenu := true - ] ifFalse:[ - keepMenu ifFalse:[ - hideMenu := true - ] - ] + y < 0 ifTrue:[ + hideMenu := true + ] ifFalse:[ + keepMenu ifFalse:[ + hideMenu := true + ] + ] ]. hideMenu ifTrue:[ self hideActiveMenu.