51 " |
51 " |
52 ! |
52 ! |
53 |
53 |
54 version |
54 version |
55 " |
55 " |
56 $Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.11 1994-10-28 03:25:11 claus Exp $ |
56 $Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.12 1994-11-17 14:38:13 claus Exp $ |
57 " |
57 " |
58 ! |
58 ! |
59 |
59 |
60 documentation |
60 documentation |
61 " |
61 " |
62 a menu view used for both pull-down-menus and pop-up-menus |
62 a menu view used for both pull-down-menus and pop-up-menus (and also, |
|
63 for nonModal menus, such as the Launchers click-menu). |
63 the action to be performed can be defined either as: |
64 the action to be performed can be defined either as: |
64 |
65 |
65 1) action:aBlockWithOneArg |
66 1) action:aBlockWithOneArg |
66 which defines a block to be called with the line number (1..n) |
67 which defines a block to be called with the line number (1..n) |
67 of the selected line. |
68 of the selected line. |
70 which defines the messages to be sent to receiver for each |
71 which defines the messages to be sent to receiver for each |
71 line. |
72 line. |
72 |
73 |
73 It is also possible to define both actionBlock and selectorArray. |
74 It is also possible to define both actionBlock and selectorArray. |
74 |
75 |
|
76 The wellknown popups are created by wrapping a MenuView into an instance of |
|
77 PopUpMenu (read the description of popupmenu). |
|
78 |
75 menu entries starting with '\c' are check-entries. |
79 menu entries starting with '\c' are check-entries. |
76 menu entries conisting of '-' alone, are separating lines. |
80 menu entries conisting of '-' alone, are separating lines. |
77 |
81 menu entries conisting of '=' alone, are double separating lines. |
|
82 " |
|
83 ! |
|
84 |
|
85 examples |
|
86 " |
78 Examples: |
87 Examples: |
79 Notice: normally, menuviews are wrapped into either a popup- |
88 Notice: normally, menuviews are wrapped into either a popup- |
80 menu or pulldown-menu. But they can also be used stand-alone |
89 menu or pulldown-menu. But they can also be used stand-alone |
81 as in: |
90 as in: |
82 |
91 |
831 subMenuShown notNil ifTrue:[ |
840 subMenuShown notNil ifTrue:[ |
832 subMenuShown superMenu:self. |
841 subMenuShown superMenu:self. |
833 " |
842 " |
834 realize the submenu in MY windowgroup |
843 realize the submenu in MY windowgroup |
835 " |
844 " |
836 subMenuShown windowGroup:windowGroup. |
845 windowGroup notNil ifTrue:[ |
837 subMenuShown windowGroup addTopView:subMenuShown. |
846 subMenuShown windowGroup:windowGroup. |
|
847 windowGroup addTopView:subMenuShown. |
|
848 ]. |
838 subMenuShown fixSize. |
849 subMenuShown fixSize. |
839 subMenuShown origin:org. |
850 subMenuShown origin:org. |
840 subMenuShown makeFullyVisible. |
851 subMenuShown makeFullyVisible. |
841 subMenuShown realize. |
852 subMenuShown realize. |
842 device synchronizeOutput. |
853 device synchronizeOutput. |
895 y:y |
907 y:y |
896 ] |
908 ] |
897 ! |
909 ! |
898 |
910 |
899 drawVisibleLine:visLineNr with:fg and:bg |
911 drawVisibleLine:visLineNr with:fg and:bg |
900 |line isSpecial special| |
912 |line isSpecial| |
901 |
913 |
902 line := self visibleAt:visLineNr. |
914 line := self visibleAt:visLineNr. |
903 |
915 |
904 isSpecial := false. |
916 isSpecial := line includes:$\. |
905 |
|
906 ((line at:1) == $\) ifTrue:[ |
|
907 special := line at:2. |
|
908 (special == $c) ifTrue:[ |
|
909 isSpecial := true |
|
910 ] |
|
911 ]. |
|
912 isSpecial ifFalse:[ |
917 isSpecial ifFalse:[ |
|
918 " |
|
919 a normal entry |
|
920 " |
913 super drawVisibleLine:visLineNr with:fg and:bg |
921 super drawVisibleLine:visLineNr with:fg and:bg |
914 ] ifTrue:[ |
922 ] ifTrue:[ |
|
923 " |
|
924 some speciality in this line (check-mark) |
|
925 " |
915 super drawVisibleLine:visLineNr "from:3" with:fg and:bg. |
926 super drawVisibleLine:visLineNr "from:3" with:fg and:bg. |
916 self drawMarkInVisibleLine:visLineNr with:fg and:bg |
927 self drawMarkInVisibleLine:visLineNr with:fg and:bg |
917 ] |
928 ] |
918 ! |
929 ! |
919 |
930 |
1010 redrawVisibleLine:visLine from:startCol to:endCol |
1021 redrawVisibleLine:visLine from:startCol to:endCol |
1011 self redrawVisibleLine:visLine |
1022 self redrawVisibleLine:visLine |
1012 ! |
1023 ! |
1013 |
1024 |
1014 redrawVisibleLine:visLineNr |
1025 redrawVisibleLine:visLineNr |
1015 |line lineNr y isSpecial isSeparatingLine right clr1 clr2| |
1026 "redefined from normal list-line drawing, to handle special |
|
1027 lines. These are: |
|
1028 lines consisting of '-' only: draw a horizontal separating line |
|
1029 lines consisting of '=' only: draw double separating line |
|
1030 empty line : leave blank |
|
1031 there may be more in the future. |
|
1032 " |
|
1033 |
|
1034 |line lineNr y isSpecial isSeparatingLine |
|
1035 isDoubleLine right clr1 clr2| |
1016 |
1036 |
1017 line := self visibleAt:visLineNr. |
1037 line := self visibleAt:visLineNr. |
1018 |
1038 |
1019 isSpecial := false. |
1039 isSpecial := isDoubleLine := isSeparatingLine := false. |
1020 (line = '-') ifTrue:[ |
1040 (line = '-') ifTrue:[ |
1021 isSeparatingLine := true. |
1041 isSeparatingLine := isSpecial := true. |
1022 isSpecial := true |
|
1023 ] ifFalse:[ |
1042 ] ifFalse:[ |
1024 (line = '') ifTrue:[ |
1043 (line = '=') ifTrue:[ |
1025 isSeparatingLine := false. |
1044 isSeparatingLine := isSpecial := isDoubleLine := true. |
1026 isSpecial := true |
1045 ] ifFalse:[ |
|
1046 (line = '') ifTrue:[ |
|
1047 isSpecial := true |
|
1048 ] |
1027 ] |
1049 ] |
1028 ]. |
1050 ]. |
|
1051 |
1029 isSpecial ifFalse:[ |
1052 isSpecial ifFalse:[ |
1030 lineNr := self visibleLineToListLine:visLineNr. |
1053 lineNr := self visibleLineToListLine:visLineNr. |
1031 (enableFlags at:lineNr) ifFalse:[ |
1054 (enableFlags at:lineNr) ifFalse:[ |
1032 self drawVisibleLine:visLineNr with:disabledFgColor and:bgColor |
1055 self drawVisibleLine:visLineNr with:disabledFgColor and:bgColor |
1033 ] ifTrue:[ |
1056 ] ifTrue:[ |
1047 self paint:bgColor. |
1070 self paint:bgColor. |
1048 self fillRectangleX:0 y:y width:width height:fontHeight. |
1071 self fillRectangleX:0 y:y width:width height:fontHeight. |
1049 |
1072 |
1050 isSeparatingLine ifTrue:[ |
1073 isSeparatingLine ifTrue:[ |
1051 y := y + (fontHeight // 2). |
1074 y := y + (fontHeight // 2). |
|
1075 isDoubleLine ifTrue:[ |
|
1076 y := y - (fontHeight // 8). |
|
1077 ]. |
1052 lineLevel == 0 ifTrue:[ |
1078 lineLevel == 0 ifTrue:[ |
1053 self paint:fgColor. |
1079 self paint:fgColor. |
1054 self displayLineFromX:0 y:y toX:width y:y |
1080 self displayLineFromX:0 y:y toX:width y:y. |
|
1081 isDoubleLine ifTrue:[ |
|
1082 y := y + (fontHeight // 4). |
|
1083 self displayLineFromX:0 y:y toX:width y:y |
|
1084 ] |
1055 ] ifFalse:[ |
1085 ] ifFalse:[ |
1056 "the inset on each side" |
1086 "the inset on each side" |
1057 |
1087 |
1058 lineLevel < 0 ifTrue:[ |
1088 lineLevel < 0 ifTrue:[ |
1059 clr1 := shadowColor. |
1089 clr1 := shadowColor. |
1060 clr2 := lightColor. |
1090 clr2 := lightColor. |
1061 ] ifFalse:[ |
1091 ] ifFalse:[ |
1062 clr1 := lightColor. |
1092 clr1 := lightColor. |
1063 clr2 := shadowColor. |
1093 clr2 := shadowColor. |
1064 ]. |
1094 ]. |
|
1095 right := width - 1 - lineInset. |
|
1096 |
1065 self paint:clr1. |
1097 self paint:clr1. |
1066 right := width - 1 - lineInset. |
|
1067 self displayLineFromX:lineInset y:y toX:right y:y. |
1098 self displayLineFromX:lineInset y:y toX:right y:y. |
1068 self paint:clr2. |
1099 self paint:clr2. |
1069 y := y + 1. |
1100 y := y + 1. |
1070 self displayLineFromX:lineInset y:y toX:right y:y |
1101 self displayLineFromX:lineInset y:y toX:right y:y. |
|
1102 isDoubleLine ifTrue:[ |
|
1103 y := y + (fontHeight // 4). |
|
1104 self displayLineFromX:lineInset y:y toX:right y:y. |
|
1105 y := y - 1. |
|
1106 self paint:clr1. |
|
1107 self displayLineFromX:lineInset y:y toX:right y:y. |
|
1108 ] |
1071 ] |
1109 ] |
1072 ] |
1110 ] |
1073 ! |
1111 ! |
1074 |
1112 |
1075 redrawFromVisibleLine:start to:stop |
1113 redrawFromVisibleLine:start to:stop |
1076 "redraw a line range" |
1114 "redraw a line range - redefined to care for special entries." |
1077 |
1115 |
1078 "the natural way to do it is: |
1116 "the natural way to do it is: |
1079 |
1117 |
1080 start to:stop do:[:visLine | |
1118 start to:stop do:[:visLine | |
1081 self redrawVisibleLine:visLine |
1119 self redrawVisibleLine:visLine |
1090 index := self visibleLineToListLine:start. |
1128 index := self visibleLineToListLine:start. |
1091 index notNil ifTrue:[ |
1129 index notNil ifTrue:[ |
1092 [current <= stop] whileTrue:[ |
1130 [current <= stop] whileTrue:[ |
1093 line := self visibleAt:current. |
1131 line := self visibleAt:current. |
1094 |
1132 |
1095 special := (line = '-') or:[(line = '') or:[(line at:1) == $\]]. |
1133 special := (line = '-') |
|
1134 or:[(line = '') |
|
1135 or:[(line at:1) == $\ |
|
1136 or:[(line = '=')]]]. |
1096 (special |
1137 (special |
1097 or:[(enableFlags at:index) not]) ifTrue:[ |
1138 or:[(enableFlags at:index) not]) ifTrue:[ |
1098 "a special case" |
1139 "a special case" |
1099 (first < current) ifTrue:[ |
1140 (first < current) ifTrue:[ |
1100 super redrawFromVisibleLine:first to:(current - 1) |
1141 super redrawFromVisibleLine:first to:(current - 1) |
1204 ] do:[ |
1245 ] do:[ |
1205 actionBlock value:(self selection) |
1246 actionBlock value:(self selection) |
1206 ] |
1247 ] |
1207 ] ifFalse:[ |
1248 ] ifFalse:[ |
1208 selectors notNil ifTrue: [ |
1249 selectors notNil ifTrue: [ |
1209 ActiveGrab == self ifTrue:[ |
1250 device activePointerGrab == self ifTrue:[ |
1210 device ungrabPointer. |
1251 device ungrabPointer. |
1211 ActiveGrab := nil. |
|
1212 ]. |
1252 ]. |
1213 (selectors isKindOf:Symbol) ifFalse:[ |
1253 (selectors isKindOf:Symbol) ifFalse:[ |
1214 (selection notNil |
1254 (selection notNil |
1215 and:[selection <= selectors size]) ifTrue:[ |
1255 and:[selection <= selectors size]) ifTrue:[ |
1216 theSelector := selectors at:selection |
1256 theSelector := selectors at:selection |