13 SimpleView subclass:#PullDownMenu |
13 SimpleView subclass:#PullDownMenu |
14 instanceVariableNames:'receiver menus titles selectors activeMenuNumber |
14 instanceVariableNames:'receiver menus titles selectors activeMenuNumber |
15 showSeparatingLines topMargin |
15 showSeparatingLines topMargin |
16 fgColor bgColor activeFgColor activeBgColor |
16 fgColor bgColor activeFgColor activeBgColor |
17 onLevel offLevel edgeStyle |
17 onLevel offLevel edgeStyle |
18 keepMenu toggleKeep' |
18 keepMenu toggleKeep raiseTopWhenActivated' |
19 classVariableNames:'DefaultFont |
19 classVariableNames:'DefaultFont |
20 DefaultViewBackground |
20 DefaultViewBackground |
21 DefaultForegroundColor |
21 DefaultForegroundColor |
22 DefaultBackgroundColor |
22 DefaultBackgroundColor |
23 DefaultHilightForegroundColor |
23 DefaultHilightForegroundColor |
340 !PullDownMenu class methodsFor:'defaults'! |
344 !PullDownMenu class methodsFor:'defaults'! |
341 |
345 |
342 updateStyleCache |
346 updateStyleCache |
343 "extract values from the styleSheet and cache them in class variables" |
347 "extract values from the styleSheet and cache them in class variables" |
344 |
348 |
345 DefaultViewBackground := StyleSheet colorAt:'pullDownMenuViewBackground'. |
349 |styleSheet| |
|
350 |
|
351 styleSheet := StyleSheet. |
|
352 |
|
353 DefaultViewBackground := styleSheet colorAt:'pullDownMenuViewBackground'. |
346 DefaultViewBackground isNil ifTrue:[ |
354 DefaultViewBackground isNil ifTrue:[ |
347 DefaultViewBackground := StyleSheet colorAt:'menuViewBackground'. |
355 DefaultViewBackground := styleSheet colorAt:'menuViewBackground'. |
348 ]. |
356 ]. |
349 DefaultForegroundColor := StyleSheet colorAt:'pullDownMenuForegroundColor'. |
357 DefaultForegroundColor := styleSheet colorAt:'pullDownMenuForegroundColor'. |
350 DefaultForegroundColor isNil ifTrue:[ |
358 DefaultForegroundColor isNil ifTrue:[ |
351 DefaultForegroundColor := StyleSheet colorAt:'menuForegroundColor'. |
359 DefaultForegroundColor := styleSheet colorAt:'menuForegroundColor'. |
352 ]. |
360 ]. |
353 DefaultBackgroundColor := StyleSheet colorAt:'pullDownMenuBackgroundColor'. |
361 DefaultBackgroundColor := styleSheet colorAt:'pullDownMenuBackgroundColor'. |
354 DefaultBackgroundColor isNil ifTrue:[ |
362 DefaultBackgroundColor isNil ifTrue:[ |
355 DefaultViewBackground notNil ifTrue:[ |
363 DefaultViewBackground notNil ifTrue:[ |
356 DefaultBackgroundColor := DefaultViewBackground |
364 DefaultBackgroundColor := DefaultViewBackground |
357 ] ifFalse:[ |
365 ] ifFalse:[ |
358 DefaultBackgroundColor := StyleSheet colorAt:'menuBackgroundColor'. |
366 DefaultBackgroundColor := styleSheet colorAt:'menuBackgroundColor'. |
359 ] |
367 ] |
360 ]. |
368 ]. |
361 DefaultHilightForegroundColor := StyleSheet colorAt:'pullDownMenuHilightForegroundColor'. |
369 DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenuHilightForegroundColor'. |
362 DefaultHilightForegroundColor isNil ifTrue:[ |
370 DefaultHilightForegroundColor isNil ifTrue:[ |
363 DefaultHilightForegroundColor := StyleSheet colorAt:'menuHilightForegroundColor'. |
371 DefaultHilightForegroundColor := styleSheet colorAt:'menuHilightForegroundColor'. |
364 ]. |
372 ]. |
365 DefaultHilightBackgroundColor := StyleSheet colorAt:'pullDownMenuHilightBackgroundColor'. |
373 DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenuHilightBackgroundColor'. |
366 DefaultHilightBackgroundColor isNil ifTrue:[ |
374 DefaultHilightBackgroundColor isNil ifTrue:[ |
367 DefaultHilightBackgroundColor := StyleSheet colorAt:'menuHilightBackgroundColor'. |
375 DefaultHilightBackgroundColor := styleSheet colorAt:'menuHilightBackgroundColor'. |
368 ]. |
376 ]. |
369 DefaultHilightLevel := StyleSheet at:'pullDownMenuHilightLevel'. |
377 DefaultHilightLevel := styleSheet at:'pullDownMenuHilightLevel'. |
370 DefaultHilightLevel isNil ifTrue:[ |
378 DefaultHilightLevel isNil ifTrue:[ |
371 DefaultHilightLevel := StyleSheet at:'menuHilightLevel' default:0. |
379 DefaultHilightLevel := styleSheet at:'menuHilightLevel' default:0. |
372 ]. |
380 ]. |
373 DefaultEdgeStyle := StyleSheet at:'pullDownMenuEdgeStyle'. |
381 DefaultEdgeStyle := styleSheet at:'pullDownMenuEdgeStyle'. |
374 DefaultKeepMenu := StyleSheet at:'pullDownMenuKeepMenu' default:false. |
382 DefaultKeepMenu := styleSheet at:'pullDownMenuKeepMenu' default:false. |
375 DefaultToggleKeep := StyleSheet at:'pullDownMenuToggleKeep' default:false. |
383 DefaultToggleKeep := styleSheet at:'pullDownMenuToggleKeep' default:false. |
376 DefaultLevel := StyleSheet at:'pullDownMenuLevel' default:1. |
384 DefaultLevel := styleSheet at:'pullDownMenuLevel' default:1. |
377 DefaultFont := StyleSheet fontAt:'pullDownMenuFont'. |
385 DefaultFont := styleSheet fontAt:'pullDownMenuFont'. |
378 DefaultFont isNil ifTrue:[ |
386 DefaultFont isNil ifTrue:[ |
379 DefaultFont := StyleSheet fontAt:'menuFont'. |
387 DefaultFont := styleSheet fontAt:'menuFont'. |
380 ]. |
388 ]. |
381 DefaultSeparatingLines := StyleSheet at:'pullDownMenuSeparatingLines' default:false. |
389 DefaultSeparatingLines := styleSheet at:'pullDownMenuSeparatingLines' default:false. |
382 |
390 |
383 " |
391 " |
384 PullDownMenu updateStyleCache |
392 PullDownMenu updateStyleCache |
385 " |
393 " |
386 ! ! |
394 ! ! |
746 idx ~~ 0 ifTrue:[^ idx]. |
775 idx ~~ 0 ifTrue:[^ idx]. |
747 ]. |
776 ]. |
748 ^ titles indexOf:stringOrNumber |
777 ^ titles indexOf:stringOrNumber |
749 ! |
778 ! |
750 |
779 |
|
780 someMenuItemLabeled:aLabel |
|
781 "find a menu item. |
|
782 Currently, in ST/X, instances of MenuItem are only created as dummy" |
|
783 |
|
784 |idx| |
|
785 |
|
786 idx := self indexOf:aLabel. |
|
787 idx ~~ 0 ifTrue:[ |
|
788 ^ MenuItem new menu:self index:idx |
|
789 ]. |
|
790 menus notNil ifTrue:[ |
|
791 menus do:[:aMenu | |
|
792 |item| |
|
793 |
|
794 aMenu notNil ifTrue:[ |
|
795 (item := aMenu someMenuItemLabeled:aLabel) notNil ifTrue:[ |
|
796 ^ item |
|
797 ] |
|
798 ] |
|
799 ] |
|
800 ]. |
|
801 ^ nil |
|
802 ! |
|
803 |
751 setMenuOrigins |
804 setMenuOrigins |
752 "adjust origins of menus when font changes" |
805 "adjust origins of menus when font changes" |
753 |
806 |
754 (font device == device) ifTrue:[ |
807 (font device == device) ifTrue:[ |
755 menus keysAndValuesDo:[:index :aMenu | |
808 menus keysAndValuesDo:[:index :aMenu | |
892 showSeparatingLines ifTrue:[ |
949 showSeparatingLines ifTrue:[ |
893 self is3D ifTrue:[ |
950 self is3D ifTrue:[ |
894 self paint:shadowColor. |
951 self paint:shadowColor. |
895 self displayLineFromX:x y:0 toX:x y:y. |
952 self displayLineFromX:x y:0 toX:x y:y. |
896 x := x + 1. |
953 x := x + 1. |
897 self paint:lightColor. |
954 clr := lightColor. |
898 ] ifFalse:[ |
955 ] ifFalse:[ |
899 self paint:fgColor. |
956 clr := fgColor. |
900 ]. |
957 ]. |
|
958 self paint:clr. |
901 self displayLineFromX:x y:0 toX:x y:y. |
959 self displayLineFromX:x y:0 toX:x y:y. |
902 x := x + 1 |
960 x := x + 1 |
903 ]. |
961 ]. |
904 index := index + 1 |
962 index := index + 1 |
905 ] |
963 ] |
906 ! |
964 ! |
907 |
965 |
908 drawTitle:stringOrImage x:x0 selected:selected |
966 drawTitle:stringOrImage x:x0 selected:selected |
909 |y w x wSpace| |
967 |y w x wSpace fg bg| |
|
968 |
|
969 selected ifTrue:[ |
|
970 fg := activeFgColor. |
|
971 bg := activeBgColor |
|
972 ] ifFalse:[ |
|
973 fg := fgColor. |
|
974 bg := bgColor |
|
975 ]. |
910 |
976 |
911 wSpace := font widthOf:' '. |
977 wSpace := font widthOf:' '. |
912 x := x0. |
978 x := x0. |
913 stringOrImage isString ifTrue:[ |
979 stringOrImage isString ifTrue:[ |
914 y := ((height - (font height)) // 2) + (font ascent) "+ topMargin". |
980 y := ((height - (font height)) // 2) + (font ascent) "+ topMargin". |
917 y := ((height - stringOrImage height) // 2) max:0. |
983 y := ((height - stringOrImage height) // 2) max:0. |
918 w := stringOrImage width |
984 w := stringOrImage width |
919 ]. |
985 ]. |
920 w := w + (wSpace * 2). |
986 w := w + (wSpace * 2). |
921 |
987 |
922 selected ifTrue:[ |
988 self paint:bg. |
923 self paint:activeBgColor |
|
924 ] ifFalse:[ |
|
925 self paint:bgColor |
|
926 ]. |
|
927 self fillRectangleX:x y:0 width:w height:height. |
989 self fillRectangleX:x y:0 width:w height:height. |
928 |
990 |
929 self is3D ifTrue:[ |
991 self is3D ifTrue:[ |
930 self drawEdgesForX:x y:0 |
992 self drawEdgesForX:x y:0 |
931 width:w |
993 width:w |
932 height:height |
994 height:height |
933 level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) |
995 level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) |
934 ]. |
996 ]. |
935 selected ifTrue:[ |
997 self paint:fg. |
936 self paint:activeFgColor |
|
937 ] ifFalse:[ |
|
938 self paint:fgColor |
|
939 ]. |
|
940 x := x + wSpace. |
998 x := x + wSpace. |
941 stringOrImage isString ifTrue:[ |
999 stringOrImage isString ifTrue:[ |
942 self displayString:stringOrImage x:x y:y |
1000 self displayString:stringOrImage x:x y:y |
943 ] ifFalse:[ |
1001 ] ifFalse:[ |
944 self displayForm:stringOrImage x:x y:y |
1002 self displayForm:stringOrImage x:x y:y |
945 ] |
1003 ] |
946 ! |
1004 ! |
947 |
1005 |
948 highlightActiveTitle |
1006 drawActiveTitleSelected:selected |
949 |x| |
1007 |x| |
950 activeMenuNumber notNil ifTrue:[ |
1008 activeMenuNumber notNil ifTrue:[ |
951 x := self titleLenUpTo:activeMenuNumber. |
1009 x := self titleLenUpTo:activeMenuNumber. |
952 self drawTitle:(titles at:activeMenuNumber) x:x selected:true |
1010 self drawTitle:(titles at:activeMenuNumber) x:x selected:selected |
953 ] |
1011 ] |
954 ! |
1012 ! |
955 |
1013 |
|
1014 highlightActiveTitle |
|
1015 self drawActiveTitleSelected:true |
|
1016 ! |
|
1017 |
956 unHighlightActiveTitle |
1018 unHighlightActiveTitle |
957 |x| |
1019 self drawActiveTitleSelected:false |
958 activeMenuNumber notNil ifTrue:[ |
|
959 x := self titleLenUpTo:activeMenuNumber. |
|
960 self drawTitle:(titles at:activeMenuNumber) x:x selected:false |
|
961 ] |
|
962 ! ! |
1020 ! ! |
963 |
1021 |
964 !PullDownMenu methodsFor:'submenu notifications'! |
1022 !PullDownMenu methodsFor:'submenu notifications'! |
965 |
1023 |
966 showActive |
1024 showActive |
1019 ]. |
1078 ]. |
1020 |
1079 |
1021 activeMenuNumber isNil ifTrue:[^self]. |
1080 activeMenuNumber isNil ifTrue:[^self]. |
1022 |
1081 |
1023 " |
1082 " |
1024 pass it on to the active menu or perform the items action |
1083 Return, space or the (virtual) MenuSelect key trigger |
|
1084 a menu entry (for non-submenu entries). |
|
1085 Otherwise, if we have a submenu open, |
|
1086 pass the key on to it ... |
1025 " |
1087 " |
1026 m := menus at:activeMenuNumber. |
1088 m := menus at:activeMenuNumber. |
1027 m isNil ifTrue:[ |
1089 m isNil ifTrue:[ |
1028 key == #Return ifTrue:[ |
1090 (key == #Return |
|
1091 or:[key == #MenuSelect |
|
1092 or:[key == Character space]]) ifTrue:[ |
1029 sel := selectors at:activeMenuNumber. |
1093 sel := selectors at:activeMenuNumber. |
1030 sel notNil ifTrue:[ |
1094 sel notNil ifTrue:[ |
1031 receiver perform:sel |
1095 receiver perform:sel |
1032 ] |
1096 ] |
1033 ]. |
1097 ]. |