PullDownMenu.st
changeset 1865 f2f2d6c93324
parent 1678 2c63b6f17997
child 1980 8c7a9ecadb5e
equal deleted inserted replaced
1864:82ffe084c0db 1865:f2f2d6c93324
    41 "
    41 "
    42 !
    42 !
    43 
    43 
    44 documentation
    44 documentation
    45 "
    45 "
       
    46     Notice: this class is obsolete now - please use a MenuPanel
       
    47     in new applications, which provides all of this functionality,
       
    48     plus more.
       
    49 
    46     PullDown menu provides the top (always visible) part of these menus. 
    50     PullDown menu provides the top (always visible) part of these menus. 
    47     It controls display of its menus, which become visible when one of the 
    51     It controls display of its menus, which become visible when one of the 
    48     PullDownMenus entries is pressed.
    52     PullDownMenus entries is pressed.
    49 
    53 
    50     A PullDownMenu itself consists of a single row of labels, which activate
    54     A PullDownMenu itself consists of a single row of labels, which activate
    58       menus                   <Collection>    the sub menus
    62       menus                   <Collection>    the sub menus
    59 
    63 
    60       titles                  <Collection>    the strings in the menu
    64       titles                  <Collection>    the strings in the menu
    61 
    65 
    62       selectors               <Collection>    the selectors to send to the menu-
    66       selectors               <Collection>    the selectors to send to the menu-
    63 					      receiver (for empty pull-menus)
    67                                               receiver (for empty pull-menus)
    64 					      if nil (the default), title entries
    68                                               if nil (the default), title entries
    65 					      do not send anything.
    69                                               do not send anything.
    66 
    70 
    67       activeMenuNumber        <Number>        the index of the currently active menu
    71       activeMenuNumber        <Number>        the index of the currently active menu
    68 
    72 
    69       showSeparatingLines     <Boolean>       show separating lines between my menu-strings
    73       showSeparatingLines     <Boolean>       show separating lines between my menu-strings
    70 
    74 
    80       offLevel                <Integer>       3D level of entry-buttons when released
    84       offLevel                <Integer>       3D level of entry-buttons when released
    81 
    85 
    82       edgeStyle               <Symbol>        how to draw edges
    86       edgeStyle               <Symbol>        how to draw edges
    83 
    87 
    84       toggleMode              <Symbol>        if #toggle, press pulls menu,
    88       toggleMode              <Symbol>        if #toggle, press pulls menu,
    85 					      another press hides it.
    89                                               another press hides it.
    86 					      if other, its hidden on release.
    90                                               if other, its hidden on release.
    87 
    91 
    88      except menus, titles and selectors, instvars are usually defined from
    92      except menus, titles and selectors, instvars are usually defined from
    89      defaults in the styleSheet; you should not care for them.
    93      defaults in the styleSheet; you should not care for them.
    90 
    94 
    91 
    95 
    92     [StyleSheet values:]
    96     [StyleSheet values:]
    93 
    97 
    94       pullDownMenuViewBackground              view background Color for the menu bar
    98       pullDownMenuViewBackground              view background Color for the menu bar
    95 					      default: menuViewBackground
    99                                               default: menuViewBackground
    96 
   100 
    97       pullDownMenuForegroundColor             foreground drawing color for the menu bar
   101       pullDownMenuForegroundColor             foreground drawing color for the menu bar
    98 					      default: menuForegroundColor
   102                                               default: menuForegroundColor
    99 
   103 
   100       pullDownMenuBackgroundColor             background drawing color for the menu bar
   104       pullDownMenuBackgroundColor             background drawing color for the menu bar
   101 					      default: menuBackgroundColor
   105                                               default: menuBackgroundColor
   102 
   106 
   103       pullDownMenuHilightForegroundColor      active foreground drawing color for the menu bar
   107       pullDownMenuHilightForegroundColor      active foreground drawing color for the menu bar
   104 					      default: menuHilightForegroundColor
   108                                               default: menuHilightForegroundColor
   105 
   109 
   106       pullDownMenuHilightBackgroundColor      active background drawing color for the menu bar
   110       pullDownMenuHilightBackgroundColor      active background drawing color for the menu bar
   107 					      default: menuHilightBackgroundColor
   111                                               default: menuHilightBackgroundColor
   108 
   112 
   109       pullDownMenuHilightLevel                level (3D only) when active
   113       pullDownMenuHilightLevel                level (3D only) when active
   110 					      default: menuHilightLevel
   114                                               default: menuHilightLevel
   111 
   115 
   112       pullDownMenuEdgeStyle                   edge style (nil or #soft)
   116       pullDownMenuEdgeStyle                   edge style (nil or #soft)
   113 
   117 
   114       pullDownMenuKeepMenu                    if true, pulled menu stays open until button
   118       pullDownMenuKeepMenu                    if true, pulled menu stays open until button
   115 					      is pressed again outside of the item-area (motif behavior)
   119                                               is pressed again outside of the item-area (motif behavior)
   116 					      if false, menu closes on release (default)
   120                                               if false, menu closes on release (default)
   117 
   121 
   118       pullDownMenuToggleKeep                  if true, pulled menu closes when an entry is pressed
   122       pullDownMenuToggleKeep                  if true, pulled menu closes when an entry is pressed
   119 					      again. Otherwise, only press outside of the items area
   123                                               again. Otherwise, only press outside of the items area
   120 					      hides it. default is false
   124                                               hides it. default is false
   121 
   125 
   122       pullDownMenuLevel                       level (3D only)
   126       pullDownMenuLevel                       level (3D only)
   123 
   127 
   124       pullDownMenuFont                        font to use for the menu bar
   128       pullDownMenuFont                        font to use for the menu bar
   125 					      default: menuFont
   129                                               default: menuFont
   126 
   130 
   127       pullDownMenuShowSeparatingLines         if true, lines are drawn between items.
   131       pullDownMenuShowSeparatingLines         if true, lines are drawn between items.
   128 					      default: false
   132                                               default: false
   129 
   133 
   130       pullDownMenuRaiseTop                    if true, topview is raised whenever an entry
   134       pullDownMenuRaiseTop                    if true, topview is raised whenever an entry
   131 					      is activated.
   135                                               is activated.
   132 					      default: true
   136                                               default: true
   133 
   137 
   134     [author:]
   138     [author:]
   135 	Claus Gittinger
   139         Claus Gittinger
   136 "
   140 "
   137 !
   141 !
   138 
   142 
   139 examples 
   143 examples 
   140 "
   144 "
   362 
   366 
   363 updateStyleCache
   367 updateStyleCache
   364     "extract values from the styleSheet and cache them in class variables"
   368     "extract values from the styleSheet and cache them in class variables"
   365 
   369 
   366     <resource: #style (#'pullDownMenu.viewBackground' #'menuView.background'
   370     <resource: #style (#'pullDownMenu.viewBackground' #'menuView.background'
   367 		       #'pullDownMenu.foregroundColor' #'menu.foregroundColor'
   371                        #'pullDownMenu.foregroundColor' #'menu.foregroundColor'
   368 		       #'pullDownMenu.backgroundColor' #'menu.backgroundColor'
   372                        #'pullDownMenu.backgroundColor' #'menu.backgroundColor'
   369 		       #'pullDownMenu.hilightForegroundColor' #'menu.hilightForegroundColor'
   373                        #'pullDownMenu.hilightForegroundColor' #'menu.hilightForegroundColor'
   370 		       #'pullDownMenu.hilightBackgroundColor' #'menu.hilightBackgroundColor'
   374                        #'pullDownMenu.hilightBackgroundColor' #'menu.hilightBackgroundColor'
   371 		       #'pullDownMenu.hilightLevel' #'menu.hilightLevel'
   375                        #'pullDownMenu.hilightLevel' #'menu.hilightLevel'
   372 		       #'pullDownMenu.edgeStyle' 
   376                        #'pullDownMenu.edgeStyle' 
   373 		       #'pullDownMenu.toggleMode'
   377                        #'pullDownMenu.toggleMode'
   374 		       #'pullDownMenu.level'
   378                        #'pullDownMenu.level'
   375 		       #'pullDownMenu.font' #'menu.font'
   379                        #'pullDownMenu.font' #'menu.font'
   376 		       #'pullDownMenu.separatingLines')>
   380                        #'pullDownMenu.separatingLines')>
   377 
   381 
   378     |styleSheet|
   382     |styleSheet|
   379 
   383 
   380     styleSheet := StyleSheet.
   384     styleSheet := StyleSheet.
   381 
   385 
   382     DefaultViewBackground := styleSheet colorAt:'pullDownMenu.viewBackground'.
   386     DefaultViewBackground := styleSheet colorAt:#'pullDownMenu.viewBackground'.
   383     DefaultViewBackground isNil ifTrue:[
   387     DefaultViewBackground isNil ifTrue:[
   384 	DefaultViewBackground := styleSheet colorAt:'menuView.background'.
   388         DefaultViewBackground := styleSheet colorAt:#'menuView.background'.
   385     ].
   389     ].
   386     DefaultForegroundColor := styleSheet colorAt:'pullDownMenu.foregroundColor'.
   390     DefaultForegroundColor := styleSheet colorAt:#'pullDownMenu.foregroundColor'.
   387     DefaultForegroundColor isNil ifTrue:[
   391     DefaultForegroundColor isNil ifTrue:[
   388 	DefaultForegroundColor := styleSheet colorAt:'menu.foregroundColor'.
   392         DefaultForegroundColor := styleSheet colorAt:#'menu.foregroundColor'.
   389     ].
   393     ].
   390     DefaultBackgroundColor := styleSheet colorAt:'pullDownMenu.backgroundColor'.
   394     DefaultBackgroundColor := styleSheet colorAt:#'pullDownMenu.backgroundColor'.
   391     DefaultBackgroundColor isNil ifTrue:[
   395     DefaultBackgroundColor isNil ifTrue:[
   392 	DefaultViewBackground notNil ifTrue:[
   396         DefaultViewBackground notNil ifTrue:[
   393 	    DefaultBackgroundColor := DefaultViewBackground
   397             DefaultBackgroundColor := DefaultViewBackground
   394 	] ifFalse:[
   398         ] ifFalse:[
   395 	    DefaultBackgroundColor := styleSheet colorAt:'menu.backgroundColor'.
   399             DefaultBackgroundColor := styleSheet colorAt:#'menu.backgroundColor'.
   396 	]
   400         ]
   397     ].
   401     ].
   398     DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenu.hilightForegroundColor'.
   402     DefaultHilightForegroundColor := styleSheet colorAt:#'pullDownMenu.hilightForegroundColor'.
   399     DefaultHilightForegroundColor isNil ifTrue:[
   403     DefaultHilightForegroundColor isNil ifTrue:[
   400 	DefaultHilightForegroundColor := styleSheet colorAt:'menu.hilightForegroundColor'.
   404         DefaultHilightForegroundColor := styleSheet colorAt:#'menu.hilightForegroundColor'.
   401     ].
   405     ].
   402     DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenu.hilightBackgroundColor'.
   406     DefaultHilightBackgroundColor := styleSheet colorAt:#'pullDownMenu.hilightBackgroundColor'.
   403     DefaultHilightBackgroundColor isNil ifTrue:[
   407     DefaultHilightBackgroundColor isNil ifTrue:[
   404 	DefaultHilightBackgroundColor := styleSheet colorAt:'menu.hilightBackgroundColor'.
   408         DefaultHilightBackgroundColor := styleSheet colorAt:#'menu.hilightBackgroundColor'.
   405     ].
   409     ].
   406     DefaultHilightLevel := styleSheet at:'pullDownMenu.hilightLevel'.
   410     DefaultHilightLevel := styleSheet at:#'pullDownMenu.hilightLevel'.
   407     DefaultHilightLevel isNil ifTrue:[
   411     DefaultHilightLevel isNil ifTrue:[
   408 	DefaultHilightLevel := styleSheet at:'menu.hilightLevel' default:0.
   412         DefaultHilightLevel := styleSheet at:#'menu.hilightLevel' default:0.
   409     ].
   413     ].
   410     DefaultEdgeStyle := styleSheet at:'pullDownMenu.edgeStyle'.
   414     DefaultEdgeStyle := styleSheet at:#'pullDownMenu.edgeStyle'.
   411     DefaultToggleMode := styleSheet at:'pullDownMenu.toggleMode' default:#toggle.
   415     DefaultToggleMode := styleSheet at:#'pullDownMenu.toggleMode' default:#toggle.
   412     DefaultLevel := styleSheet at:'pullDownMenu.level' default:1.
   416     DefaultLevel := styleSheet at:#'pullDownMenu.level' default:1.
   413     DefaultFont := styleSheet fontAt:'pullDownMenu.font'.
   417     DefaultFont := styleSheet fontAt:#'pullDownMenu.font'.
   414     DefaultFont isNil ifTrue:[DefaultFont := styleSheet fontAt:'menu.font'].
   418     DefaultFont isNil ifTrue:[DefaultFont := styleSheet fontAt:#'menu.font'].
   415     DefaultSeparatingLines := styleSheet at:'pullDownMenu.separatingLines' default:false.
   419     DefaultSeparatingLines := styleSheet at:#'pullDownMenu.separatingLines' default:false.
   416 
   420 
   417     "
   421     "
   418      PullDownMenu updateStyleCache
   422      PullDownMenu updateStyleCache
   419     "
   423     "
   420 
   424 
  1062 
  1066 
  1063     device ungrabPointer.
  1067     device ungrabPointer.
  1064     device ungrabKeyboard.
  1068     device ungrabKeyboard.
  1065 
  1069 
  1066     (y between:0 and:height) ifTrue:[
  1070     (y between:0 and:height) ifTrue:[
  1067 	titleIndex := self titleIndexForX:x.
  1071         titleIndex := self titleIndexForX:x.
  1068     ].
  1072     ].
  1069 
  1073 
  1070     "
  1074     "
  1071      now, titleIndex is non-nil if pressed within myself
  1075      now, titleIndex is non-nil if pressed within myself
  1072     "
  1076     "
  1073     (titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
  1077     (titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
  1074 	"/ pressed on another item
  1078         "/ pressed on another item
  1075 	m := self pullMenu:titleIndex.
  1079         m := self pullMenu:titleIndex.
  1076 	(toggleMode == #toggle) ifTrue:[
  1080         (toggleMode == #toggle) ifTrue:[
  1077 	    device grabPointerInView:self.
  1081             device grabPointerInView:self.
  1078 	    device grabKeyboardInView:self.
  1082             device grabKeyboardInView:self.
  1079 "/            self cursor:Cursor upRightArrow
  1083 "/            self cursor:Cursor upRightArrow
  1080 	]
  1084         ]
  1081     ] ifFalse:[
  1085     ] ifFalse:[
  1082 	titleIndex == activeMenuNumber ifTrue:[
  1086         titleIndex == activeMenuNumber ifTrue:[
  1083 	    "/ pressed on same item
  1087             "/ pressed on same item
  1084 	    (toggleMode ~~ #toggle) ifTrue:[
  1088             (toggleMode ~~ #toggle) ifTrue:[
  1085 		"same pressed again ... stay"
  1089                 "same pressed again ... stay"
  1086 		titleIndex notNil ifTrue:[
  1090                 titleIndex notNil ifTrue:[
  1087 		    device grabPointerInView:self.
  1091                     device grabPointerInView:self.
  1088 		    device grabKeyboardInView:self.
  1092                     device grabKeyboardInView:self.
  1089 		].
  1093                 ].
  1090 	    ] ifFalse:[
  1094             ] ifFalse:[
  1091 		self hideActiveMenu.
  1095                 self hideActiveMenu.
  1092 	    ].
  1096             ].
  1093 	    ^ self
  1097             ^ self
  1094 	].
  1098         ].
  1095 
  1099 
  1096 	"/ pressed outside
  1100         "/ pressed outside
  1097 
  1101 
  1098 	activeMenuNumber isNil ifTrue:[^self].
  1102         activeMenuNumber isNil ifTrue:[^self].
  1099 
  1103 
  1100 	activeMenu := menus at:activeMenuNumber.
  1104         activeMenu := menus at:activeMenuNumber.
  1101 	activeLeft := activeMenu left.
  1105         activeLeft := activeMenu left.
  1102 	(x between:activeLeft and:(activeMenu right)) ifTrue:[
  1106         (x between:activeLeft and:(activeMenu right)) ifTrue:[
  1103 	    activeTop := activeMenu top.
  1107             activeTop := activeMenu top.
  1104 	    (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1108             (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1105 		"/ pressed inside currently pulled menu
  1109 
  1106 		activeMenu buttonPress:button x:(x - activeLeft) y:(y - activeTop).
  1110                 "/ pressed inside currently pulled menu
  1107 		^ self
  1111                 activeMenu buttonPress:button x:(x - activeLeft) y:(y - activeTop).
  1108 	    ].
  1112                 ^ self
  1109 	].
  1113             ].
  1110 
  1114         ].
  1111 	"/ somewhere else
  1115 
  1112 	self hideActiveMenu
  1116         "/ somewhere else
       
  1117         self hideActiveMenu.
  1113     ]
  1118     ]
  1114 
  1119 
  1115     "Modified: 6.3.1996 / 17:14:16 / cg"
  1120     "Modified: 6.3.1996 / 17:14:16 / cg"
  1116 !
  1121 !
  1117 
  1122 
  1291      and a grab was set"
  1296      and a grab was set"
  1292 
  1297 
  1293     |m|
  1298     |m|
  1294 
  1299 
  1295     activeMenuNumber notNil ifTrue:[
  1300     activeMenuNumber notNil ifTrue:[
  1296 	(m := menus at:activeMenuNumber) notNil ifTrue:[
  1301         (m := menus at:activeMenuNumber) notNil ifTrue:[
  1297 	    m beInvisible.
  1302             m beInvisible.
  1298 	].
  1303         ].
  1299 	self unHighlightActiveTitle.
  1304         self unHighlightActiveTitle.
  1300 	activeMenuNumber := nil
  1305         activeMenuNumber := nil
  1301     ].
  1306     ].
  1302     aBoolean ifTrue:[
  1307     aBoolean ifTrue:[
  1303 	device ungrabKeyboard.
  1308         device ungrabKeyboard.
  1304 	device ungrabPointer. 
  1309         device ungrabPointer. 
  1305 "/        self cursor:Cursor normal
  1310 "/        self cursor:Cursor normal
  1306     ].
  1311     ].
  1307 
  1312 
  1308     "Modified: 6.3.1996 / 17:14:21 / cg"
  1313     "Modified: 6.3.1996 / 17:14:21 / cg"
  1309 !
  1314 !
  1318     activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
  1323     activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
  1319     activeMenuNumber := aNumber.
  1324     activeMenuNumber := aNumber.
  1320     subMenu := menus at:aNumber.
  1325     subMenu := menus at:aNumber.
  1321 
  1326 
  1322     raiseTopWhenActivated ifTrue:[
  1327     raiseTopWhenActivated ifTrue:[
  1323 	self topView raise.
  1328         self topView raise.
  1324     ].
  1329     ].
  1325 
  1330 
  1326     (activeMenuNumber notNil 
  1331     (activeMenuNumber notNil 
  1327     and:[
  1332     and:[
  1328 	 subMenu notNil
  1333          subMenu notNil
  1329 	 or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[
  1334          or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[
  1330 	    self highlightActiveTitle.
  1335             self highlightActiveTitle.
  1331 	 ].
  1336          ].
  1332 
  1337 
  1333     subMenu notNil ifTrue:[
  1338     subMenu notNil ifTrue:[
  1334 	subMenu origin:((left + (self titleLenUpTo:aNumber)) 
  1339         subMenu origin:((left + (self titleLenUpTo:aNumber)) 
  1335 		       @
  1340                        @
  1336 		       (posY := height + subMenu borderWidth)).
  1341                        (posY := height + subMenu borderWidth)).
  1337 	subMenu hiddenOnRealize:false.
  1342         subMenu hiddenOnRealize:false.
  1338 	subMenu setSelection:nil.
  1343         subMenu setSelection:nil.
  1339 	subMenu create.
  1344         subMenu create.
  1340 	subMenu saveUnder:true.
  1345         subMenu saveUnder:true.
  1341 	subMenu superMenu:self.
  1346         subMenu superMenu:self.
  1342 
  1347 
  1343 	subMenu right > (r := self right) ifTrue:[
  1348         subMenu right > (r := self right) ifTrue:[
  1344 	    subMenu origin:((r - subMenu width) @ posY).
  1349             subMenu origin:((r - subMenu width) @ posY).
  1345 	].
  1350         ].
  1346 	subMenu raise show.
  1351         subMenu raise show.
  1347 
  1352 
  1348 	(styleSheet at:#'pullDownMenu.autoselectFirst') == true ifTrue:[
  1353         (styleSheet at:#'pullDownMenu.autoselectFirst') == true ifTrue:[
  1349 	    subMenu setSelection:1
  1354             subMenu setSelection:1
  1350 	]
  1355         ]
  1351     ].
  1356     ].
  1352     ^ subMenu
  1357     ^ subMenu
  1353 
  1358 
  1354     "Modified: / 26.10.1997 / 17:04:00 / cg"
  1359     "Modified: / 26.10.1997 / 17:04:00 / cg"
  1355 !
  1360 !
  1424 !
  1429 !
  1425 
  1430 
  1426 initStyle
  1431 initStyle
  1427     "initialize style specifics"
  1432     "initialize style specifics"
  1428 
  1433 
  1429     <resource: #style (#name)>
  1434     <resource: #style (#name #'pullDownMenu.raiseTop')>
  1430 
  1435 
  1431     |style|
  1436     |style|
  1432 
  1437 
  1433     super initStyle.
  1438     super initStyle.
  1434 
  1439 
  1496     ].
  1501     ].
  1497     DefaultLightColor notNil ifTrue:[
  1502     DefaultLightColor notNil ifTrue:[
  1498         lightColor := DefaultLightColor
  1503         lightColor := DefaultLightColor
  1499     ].
  1504     ].
  1500 
  1505 
  1501     raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true.
  1506     raiseTopWhenActivated := styleSheet at:#'pullDownMenu.raiseTop' default:true.
  1502 
  1507 
  1503     "Modified: / 15.9.1998 / 22:58:42 / cg"
  1508     "Modified: / 15.9.1998 / 22:58:42 / cg"
  1504 !
  1509 !
  1505 
  1510 
  1506 initialize
  1511 initialize
  1784 ! !
  1789 ! !
  1785 
  1790 
  1786 !PullDownMenu class methodsFor:'documentation'!
  1791 !PullDownMenu class methodsFor:'documentation'!
  1787 
  1792 
  1788 version
  1793 version
  1789     ^ '$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.84 1998-09-18 15:27:32 cg Exp $'
  1794     ^ '$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.85 1999-04-24 12:46:56 cg Exp $'
  1790 ! !
  1795 ! !