PullDMenu.st
changeset 1403 ddc59498d1c3
parent 1377 56fd9ea18a26
child 1607 2d277721aa34
equal deleted inserted replaced
1402:58d9fbdb3d21 1403:ddc59498d1c3
    11 "
    11 "
    12 
    12 
    13 View subclass:#PullDownMenu
    13 View subclass:#PullDownMenu
    14 	instanceVariableNames:'receiver menus titles selectors activeMenuNumber
    14 	instanceVariableNames:'receiver menus titles selectors activeMenuNumber
    15 		showSeparatingLines topMargin fgColor bgColor activeFgColor
    15 		showSeparatingLines topMargin fgColor bgColor activeFgColor
    16 		activeBgColor onLevel offLevel edgeStyle keepMenu toggleKeep
    16 		activeBgColor onLevel offLevel edgeStyle toggleMode toggleKeep
    17 		raiseTopWhenActivated actions'
    17 		raiseTopWhenActivated actions'
    18 	classVariableNames:'DefaultViewBackground DefaultForegroundColor
    18 	classVariableNames:'DefaultViewBackground DefaultForegroundColor
    19 		DefaultBackgroundColor DefaultHilightForegroundColor
    19 		DefaultBackgroundColor DefaultHilightForegroundColor
    20 		DefaultHilightBackgroundColor DefaultLevel DefaultHilightLevel
    20 		DefaultHilightBackgroundColor DefaultLevel DefaultHilightLevel
    21 		DefaultShadowColor DefaultLightColor DefaultEdgeStyle
    21 		DefaultShadowColor DefaultLightColor DefaultEdgeStyle
    22 		DefaultKeepMenu DefaultToggleKeep DefaultSeparatingLines'
    22 		DefaultToggleMode DefaultKeepMenu DefaultToggleKeep DefaultSeparatingLines'
    23 	poolDictionaries:''
    23 	poolDictionaries:''
    24 	category:'Views-Menus'
    24 	category:'Views-Menus'
    25 !
    25 !
    26 
    26 
    27 !PullDownMenu class methodsFor:'documentation'!
    27 !PullDownMenu class methodsFor:'documentation'!
    57       menus                   <Collection>    the sub menus
    57       menus                   <Collection>    the sub menus
    58 
    58 
    59       titles                  <Collection>    the strings in the menu
    59       titles                  <Collection>    the strings in the menu
    60 
    60 
    61       selectors               <Collection>    the selectors to send to the menu-
    61       selectors               <Collection>    the selectors to send to the menu-
    62                                               receiver (for empty pull-menus)
    62 					      receiver (for empty pull-menus)
    63                                               if nil (the default), title entries
    63 					      if nil (the default), title entries
    64                                               do not send anything.
    64 					      do not send anything.
    65 
    65 
    66       activeMenuNumber        <Number>        the index of the currently active menu
    66       activeMenuNumber        <Number>        the index of the currently active menu
    67 
    67 
    68       showSeparatingLines     <Boolean>       show separating lines between my menu-strings
    68       showSeparatingLines     <Boolean>       show separating lines between my menu-strings
    69 
    69 
    78       onLevel                 <Integer>       3D level of entry-buttons when pressed
    78       onLevel                 <Integer>       3D level of entry-buttons when pressed
    79       offLevel                <Integer>       3D level of entry-buttons when released
    79       offLevel                <Integer>       3D level of entry-buttons when released
    80 
    80 
    81       edgeStyle               <Symbol>        how to draw edges
    81       edgeStyle               <Symbol>        how to draw edges
    82 
    82 
    83       keepmenu                <Boolean>       if on, pulled menu stays on click,
    83       toggleMode              <Symbol>        if #toggle, press pulls menu,
    84                                               till clicked again (motif & windows behavior)
    84 					      another press hides it.
    85 
    85 					      if other, its hidden on release.
    86       toggleKeep              <Boolean>       if on and keepMenu is on,
       
    87                                               clicking again on label closes menu
       
    88 
    86 
    89      except menus, titles and selectors, instvars are usually defined from
    87      except menus, titles and selectors, instvars are usually defined from
    90      defaults in the styleSheet; you should not care for them.
    88      defaults in the styleSheet; you should not care for them.
    91 
    89 
    92 
    90 
    93     [StyleSheet values:]
    91     [StyleSheet values:]
    94 
    92 
    95       pullDownMenuViewBackground              view background Color for the menu bar
    93       pullDownMenuViewBackground              view background Color for the menu bar
    96                                               default: menuViewBackground
    94 					      default: menuViewBackground
    97 
    95 
    98       pullDownMenuForegroundColor             foreground drawing color for the menu bar
    96       pullDownMenuForegroundColor             foreground drawing color for the menu bar
    99                                               default: menuForegroundColor
    97 					      default: menuForegroundColor
   100 
    98 
   101       pullDownMenuBackgroundColor             background drawing color for the menu bar
    99       pullDownMenuBackgroundColor             background drawing color for the menu bar
   102                                               default: menuBackgroundColor
   100 					      default: menuBackgroundColor
   103 
   101 
   104       pullDownMenuHilightForegroundColor      active foreground drawing color for the menu bar
   102       pullDownMenuHilightForegroundColor      active foreground drawing color for the menu bar
   105                                               default: menuHilightForegroundColor
   103 					      default: menuHilightForegroundColor
   106 
   104 
   107       pullDownMenuHilightBackgroundColor      active background drawing color for the menu bar
   105       pullDownMenuHilightBackgroundColor      active background drawing color for the menu bar
   108                                               default: menuHilightBackgroundColor
   106 					      default: menuHilightBackgroundColor
   109 
   107 
   110       pullDownMenuHilightLevel                level (3D only) when active
   108       pullDownMenuHilightLevel                level (3D only) when active
   111                                               default: menuHilightLevel
   109 					      default: menuHilightLevel
   112 
   110 
   113       pullDownMenuEdgeStyle                   edge style (nil or #soft)
   111       pullDownMenuEdgeStyle                   edge style (nil or #soft)
   114 
   112 
   115       pullDownMenuKeepMenu                    if true, pulled menu stays open until button
   113       pullDownMenuKeepMenu                    if true, pulled menu stays open until button
   116                                               is pressed again outside of the item-area (motif behavior)
   114 					      is pressed again outside of the item-area (motif behavior)
   117                                               if false, menu closes on release (default)
   115 					      if false, menu closes on release (default)
   118 
   116 
   119       pullDownMenuToggleKeep                  if true, pulled menu closes when an entry is pressed
   117       pullDownMenuToggleKeep                  if true, pulled menu closes when an entry is pressed
   120                                               again. Otherwise, only press outside of the items area
   118 					      again. Otherwise, only press outside of the items area
   121                                               hides it. default is false
   119 					      hides it. default is false
   122 
   120 
   123       pullDownMenuLevel                       level (3D only)
   121       pullDownMenuLevel                       level (3D only)
   124 
   122 
   125       pullDownMenuFont                        font to use for the menu bar
   123       pullDownMenuFont                        font to use for the menu bar
   126                                               default: menuFont
   124 					      default: menuFont
   127 
   125 
   128       pullDownMenuShowSeparatingLines         if true, lines are drawn between items.
   126       pullDownMenuShowSeparatingLines         if true, lines are drawn between items.
   129                                               default: false
   127 					      default: false
   130 
   128 
   131       pullDownMenuRaiseTop                    if true, topview is raised whenever an entry
   129       pullDownMenuRaiseTop                    if true, topview is raised whenever an entry
   132                                               is activated.
   130 					      is activated.
   133                                               default: true
   131 					      default: true
   134 
   132 
   135     [author:]
   133     [author:]
   136         Claus Gittinger
   134 	Claus Gittinger
   137 "
   135 "
   138 !
   136 !
   139 
   137 
   140 examples 
   138 examples 
   141 "
   139 "
   142   with default level (from styleSheets 'pullDownMenuLevel' setting):
   140   with default level (from styleSheets 'pullDownMenuLevel' setting):
   143                                                                         [exBegin]
   141 									[exBegin]
   144         |top menu|
   142 	|top menu|
   145 
   143 
   146         top := StandardSystemView new.
   144 	top := StandardSystemView new.
   147         top extent:300@300.
   145 	top extent:300@300.
   148 
   146 
   149         menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   147 	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   150         menu labels:#('foo' 'bar').
   148 	menu labels:#('foo' 'bar').
   151         menu selectors:#(foo bar).
   149 	menu selectors:#(foo bar).
   152         menu at:#foo
   150 	menu at:#foo
   153              putLabels:#('foo1' 'foo2' 'foo3')
   151 	     putLabels:#('foo1' 'foo2' 'foo3')
   154              selectors:#(foo1 foo2 foo3)
   152 	     selectors:#(foo1 foo2 foo3)
   155              receiver:nil.
   153 	     receiver:nil.
   156         menu at:#bar 
   154 	menu at:#bar 
   157              putLabels:#('bar1' 'bar2' 'bar3')
   155 	     putLabels:#('bar1' 'bar2' 'bar3')
   158              selectors:#(bar1 bar2 bar3)
   156 	     selectors:#(bar1 bar2 bar3)
   159              receiver:nil.
   157 	     receiver:nil.
   160         top open
   158 	top open
   161                                                                         [exEnd]
   159 									[exEnd]
   162 
   160 
   163   with a defined level:
   161   with a defined level:
   164                                                                         [exBegin]
   162 									[exBegin]
   165         |top menu|
   163 	|top menu|
   166 
   164 
   167         top := StandardSystemView new.
   165 	top := StandardSystemView new.
   168         top extent:300@300.
   166 	top extent:300@300.
   169 
   167 
   170         menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   168 	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   171         menu level:1.
   169 	menu level:1.
   172         menu labels:#('foo' 'bar').
   170 	menu labels:#('foo' 'bar').
   173         menu selectors:#(foo bar).
   171 	menu selectors:#(foo bar).
   174         menu at:#foo
   172 	menu at:#foo
   175              putLabels:#('foo1' 'foo2' 'foo3')
   173 	     putLabels:#('foo1' 'foo2' 'foo3')
   176              selectors:#(foo1 foo2 foo3)
   174 	     selectors:#(foo1 foo2 foo3)
   177              receiver:nil.
   175 	     receiver:nil.
   178         menu at:#bar 
   176 	menu at:#bar 
   179              putLabels:#('bar1' 'bar2' 'bar3')
   177 	     putLabels:#('bar1' 'bar2' 'bar3')
   180              selectors:#(bar1 bar2 bar3)
   178 	     selectors:#(bar1 bar2 bar3)
   181              receiver:nil.
   179 	     receiver:nil.
   182         top open
   180 	top open
   183                                                                         [exEnd]
   181 									[exEnd]
   184 
   182 
   185 
   183 
   186     empty entries are possible as selectable items (with non-nil seletor) ...
   184     empty entries are possible as selectable items (with non-nil seletor) ...
   187                                                                         [exBegin]
   185 									[exBegin]
   188         |top menu|
   186 	|top menu|
   189 
   187 
   190         top := StandardSystemView new.
   188 	top := StandardSystemView new.
   191         top extent:300@300.
   189 	top extent:300@300.
   192 
   190 
   193         menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   191 	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   194         menu labels:#('foo' 'bar' 'baz').
   192 	menu labels:#('foo' 'bar' 'baz').
   195         menu selectors:#(foo bar baz).
   193 	menu selectors:#(foo bar baz).
   196         menu at:#foo
   194 	menu at:#foo
   197              putLabels:#('foo1' 'foo2' 'foo3')
   195 	     putLabels:#('foo1' 'foo2' 'foo3')
   198              selectors:#(foo1 foo2 foo3)
   196 	     selectors:#(foo1 foo2 foo3)
   199              receiver:nil.
   197 	     receiver:nil.
   200         menu at:#baz 
   198 	menu at:#baz 
   201              putLabels:#('baz1' 'baz2' 'baz3')
   199 	     putLabels:#('baz1' 'baz2' 'baz3')
   202              selectors:#(baz1 baz2 baz3)
   200 	     selectors:#(baz1 baz2 baz3)
   203              receiver:nil.
   201 	     receiver:nil.
   204         top open
   202 	top open
   205                                                                         [exEnd]
   203 									[exEnd]
   206 
   204 
   207 
   205 
   208     ... or as separators (with nil selector)
   206     ... or as separators (with nil selector)
   209                                                                         [exBegin]
   207 									[exBegin]
   210         |top menu|
   208 	|top menu|
   211 
   209 
   212         top := StandardSystemView new.
   210 	top := StandardSystemView new.
   213         top extent:500@200.
   211 	top extent:500@200.
   214 
   212 
   215         menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   213 	menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
   216         menu labels:#('foo' '    ' 'bar' ' baz' '    ' 'moreFoo' 'moreBar' 'moreBaz').
   214 	menu labels:#('foo' '    ' 'bar' ' baz' '    ' 'moreFoo' 'moreBar' 'moreBaz').
   217         menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz).
   215 	menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz).
   218         menu at:#foo
   216 	menu at:#foo
   219              putLabels:#('foo1' 'foo2' 'foo3')
   217 	     putLabels:#('foo1' 'foo2' 'foo3')
   220              selectors:#(foo1 foo2 foo3)
   218 	     selectors:#(foo1 foo2 foo3)
   221              receiver:nil.
   219 	     receiver:nil.
   222         menu at:#bar 
   220 	menu at:#bar 
   223              putLabels:#('bar1' 'bar2' 'bar3')
   221 	     putLabels:#('bar1' 'bar2' 'bar3')
   224              selectors:#(bar1 bar2 bar3)
   222 	     selectors:#(bar1 bar2 bar3)
   225              receiver:nil.
   223 	     receiver:nil.
   226         menu at:#baz 
   224 	menu at:#baz 
   227              putLabels:#('baz1' 'baz2' 'baz3')
   225 	     putLabels:#('baz1' 'baz2' 'baz3')
   228              selectors:#(baz1 baz2 baz3)
   226 	     selectors:#(baz1 baz2 baz3)
   229              receiver:nil.
   227 	     receiver:nil.
   230         top open
   228 	top open
   231                                                                         [exEnd]
   229 									[exEnd]
   232 
   230 
   233 
   231 
   234 
   232 
   235     use the menus default height
   233     use the menus default height
   236                                                                         [exBegin]
   234 									[exBegin]
   237         |top menu|
   235 	|top menu|
   238 
   236 
   239         top := StandardSystemView new.
   237 	top := StandardSystemView new.
   240         top extent:300@300.
   238 	top extent:300@300.
   241 
   239 
   242         menu := PullDownMenu in:top.
   240 	menu := PullDownMenu in:top.
   243         menu origin:0.0@0.0 corner:1.0@(menu height).
   241 	menu origin:0.0@0.0 corner:1.0@(menu height).
   244         menu labels:#('foo' 'bar').
   242 	menu labels:#('foo' 'bar').
   245         menu selectors:#(foo bar).
   243 	menu selectors:#(foo bar).
   246         menu at:#foo
   244 	menu at:#foo
   247              putLabels:#('foo1' 'foo2' 'foo3')
   245 	     putLabels:#('foo1' 'foo2' 'foo3')
   248              selectors:#(foo1 foo2 foo3)
   246 	     selectors:#(foo1 foo2 foo3)
   249              receiver:nil.
   247 	     receiver:nil.
   250         top open
   248 	top open
   251                                                                         [exEnd]
   249 									[exEnd]
   252 
   250 
   253 
   251 
   254 
   252 
   255     although you can change the font, colors etc. (as shown below)
   253     although you can change the font, colors etc. (as shown below)
   256     you should NOT do it - since if you do so, the styleSheet settings
   254     you should NOT do it - since if you do so, the styleSheet settings
   257     are ineffective (which users probably won't like)
   255     are ineffective (which users probably won't like)
   258     BTW: The styleSheet entries for below are pullDownMenuForegroundColor,
   256     BTW: The styleSheet entries for below are pullDownMenuForegroundColor,
   259          pullDownMenuBackgroundColor and pullDownMenuFont
   257 	 pullDownMenuBackgroundColor and pullDownMenuFont
   260                                                                         [exBegin]
   258 									[exBegin]
   261         |top menu|
   259 	|top menu|
   262 
   260 
   263         top := StandardSystemView new.
   261 	top := StandardSystemView new.
   264         menu := PullDownMenu in:top.
   262 	menu := PullDownMenu in:top.
   265         menu font:(Font family:'courier' size:20).
   263 	menu font:(Font family:'courier' size:20).
   266         menu foregroundColor:Color red.
   264 	menu foregroundColor:Color red.
   267         menu backgroundColor:Color yellow.
   265 	menu backgroundColor:Color yellow.
   268         menu viewBackground:Color green.
   266 	menu viewBackground:Color green.
   269         menu showSeparatingLines:true.
   267 	menu showSeparatingLines:true.
   270 
   268 
   271         menu origin:0.0@0.0 corner:1.0@(menu height).
   269 	menu origin:0.0@0.0 corner:1.0@(menu height).
   272         menu labels:#('foo' 'bar').
   270 	menu labels:#('foo' 'bar').
   273         menu selectors:#(foo bar).
   271 	menu selectors:#(foo bar).
   274         menu at:#foo
   272 	menu at:#foo
   275              putLabels:#('foo1' 'foo2' 'foo3')
   273 	     putLabels:#('foo1' 'foo2' 'foo3')
   276              selectors:#(foo1 foo2 foo3)
   274 	     selectors:#(foo1 foo2 foo3)
   277              receiver:nil.
   275 	     receiver:nil.
   278         (menu menuAt:#foo) font:(Font family:'courier' size:36).
   276 	(menu menuAt:#foo) font:(Font family:'courier' size:36).
   279         top open
   277 	top open
   280                                                                         [exEnd]
   278 									[exEnd]
   281 
   279 
   282 
   280 
   283     you can use icons, too ...
   281     you can use icons, too ...
   284                                                                         [exBegin]
   282 									[exBegin]
   285         |labels top menu|
   283 	|labels top menu|
   286 
   284 
   287         top := StandardSystemView new.
   285 	top := StandardSystemView new.
   288         top extent:300@300.
   286 	top extent:300@300.
   289 
   287 
   290         menu := PullDownMenu in:top.
   288 	menu := PullDownMenu in:top.
   291         menu origin:0.0@0.0 corner:1.0@(menu height).
   289 	menu origin:0.0@0.0 corner:1.0@(menu height).
   292         labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
   290 	labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
   293                         with:'foo'
   291 			with:'foo'
   294                         with:'bar'.
   292 			with:'bar'.
   295         menu labels:labels.
   293 	menu labels:labels.
   296         menu selectors:#(about foo bar).
   294 	menu selectors:#(about foo bar).
   297         menu at:#about 
   295 	menu at:#about 
   298              putLabels:#('about PullDownMenus')
   296 	     putLabels:#('about PullDownMenus')
   299              selectors:#(aboutMenus)
   297 	     selectors:#(aboutMenus)
   300              receiver:nil.
   298 	     receiver:nil.
   301         menu at:#foo
   299 	menu at:#foo
   302              putLabels:#('foo1' 'foo2' 'foo3')
   300 	     putLabels:#('foo1' 'foo2' 'foo3')
   303              selectors:#(foo1 foo2 foo3)
   301 	     selectors:#(foo1 foo2 foo3)
   304              receiver:nil.
   302 	     receiver:nil.
   305         top open
   303 	top open
   306                                                                         [exEnd]
   304 									[exEnd]
   307 
   305 
   308 
   306 
   309     a concrete example (combining things described above)
   307     a concrete example (combining things described above)
   310     (using a Plug, since we have no application class here):
   308     (using a Plug, since we have no application class here):
   311                                                                         [exBegin]
   309 									[exBegin]
   312         |labels top menu textView appModel|
   310 	|labels top menu textView appModel|
   313 
   311 
   314         appModel := Plug new.
   312 	appModel := Plug new.
   315         appModel respondTo:#quit with:[top destroy].
   313 	appModel respondTo:#quit with:[top destroy].
   316         appModel respondTo:#showAbout with:[self information:'some info here ...'].
   314 	appModel respondTo:#showAbout with:[self information:'some info here ...'].
   317         appModel respondTo:#help with:[self information:'some help here ...'].
   315 	appModel respondTo:#help with:[self information:'some help here ...'].
   318 
   316 
   319         top := StandardSystemView new.
   317 	top := StandardSystemView new.
   320         top extent:300@300.
   318 	top extent:300@300.
   321 
   319 
   322         menu := PullDownMenu in:top.
   320 	menu := PullDownMenu in:top.
   323         menu receiver:appModel.
   321 	menu receiver:appModel.
   324         menu origin:0.0@0.0 corner:1.0@(menu height).
   322 	menu origin:0.0@0.0 corner:1.0@(menu height).
   325 
   323 
   326         textView := ScrollableView forView:(EditTextView new).
   324 	textView := ScrollableView forView:(EditTextView new).
   327         textView origin:0.0@menu height corner:1.0@1.0.
   325 	textView origin:0.0@menu height corner:1.0@1.0.
   328         top addSubView:textView.
   326 	top addSubView:textView.
   329 
   327 
   330         labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
   328 	labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
   331                         with:'file'
   329 			with:'file'
   332                         with:'edit'
   330 			with:'edit'
   333                         with:'help'.
   331 			with:'help'.
   334         menu labels:labels.
   332 	menu labels:labels.
   335         menu selectors:#(about file edit help).
   333 	menu selectors:#(about file edit help).
   336         menu at:#about 
   334 	menu at:#about 
   337              putLabels:#('about PullDownMenus')
   335 	     putLabels:#('about PullDownMenus')
   338              selectors:#(showAbout)
   336 	     selectors:#(showAbout)
   339              receiver:appModel.
   337 	     receiver:appModel.
   340         menu at:#file 
   338 	menu at:#file 
   341              putLabels:#('quit')
   339 	     putLabels:#('quit')
   342              selectors:#(quit)
   340 	     selectors:#(quit)
   343              receiver:appModel.
   341 	     receiver:appModel.
   344         menu at:#edit 
   342 	menu at:#edit 
   345              putLabels:#('copy' 'cut' 'paste')
   343 	     putLabels:#('copy' 'cut' 'paste')
   346              selectors:#(copySelection cut paste)
   344 	     selectors:#(copySelection cut paste)
   347              receiver:textView.
   345 	     receiver:textView.
   348         top open
   346 	top open
   349                                                                         [exEnd]
   347 									[exEnd]
   350 "
   348 "
   351 
   349 
   352 ! !
   350 ! !
   353 
   351 
   354 !PullDownMenu class methodsFor:'instance creation'!
   352 !PullDownMenu class methodsFor:'instance creation'!
   363 
   361 
   364 updateStyleCache
   362 updateStyleCache
   365     "extract values from the styleSheet and cache them in class variables"
   363     "extract values from the styleSheet and cache them in class variables"
   366 
   364 
   367     <resource: #style (#'pullDownMenu.viewBackground' #'menuView.background'
   365     <resource: #style (#'pullDownMenu.viewBackground' #'menuView.background'
   368                        #'pullDownMenu.foregroundColor' #'menu.foregroundColor'
   366 		       #'pullDownMenu.foregroundColor' #'menu.foregroundColor'
   369                        #'pullDownMenu.backgroundColor' #'menu.backgroundColor'
   367 		       #'pullDownMenu.backgroundColor' #'menu.backgroundColor'
   370                        #'pullDownMenu.hilightForegroundColor' #'menu.hilightForegroundColor'
   368 		       #'pullDownMenu.hilightForegroundColor' #'menu.hilightForegroundColor'
   371                        #'pullDownMenu.hilightBackgroundColor' #'menu.hilightBackgroundColor'
   369 		       #'pullDownMenu.hilightBackgroundColor' #'menu.hilightBackgroundColor'
   372                        #'pullDownMenu.hilightLevel' #'menu.hilightLevel'
   370 		       #'pullDownMenu.hilightLevel' #'menu.hilightLevel'
   373                        #'pullDownMenu.edgeStyle' #'pullDownMenu.keepMenu'
   371 		       #'pullDownMenu.edgeStyle' 
   374                        #'pullDownMenu.toggleKeep' #'pullDownMenu.level'
   372 		       #'pullDownMenu.toggleMode'
   375                        #'pullDownMenu.font' #'menu.font'
   373 		       #'pullDownMenu.level'
   376                        #'pullDownMenu.separatingLines')>
   374 		       #'pullDownMenu.font' #'menu.font'
       
   375 		       #'pullDownMenu.separatingLines')>
   377 
   376 
   378     |styleSheet|
   377     |styleSheet|
   379 
   378 
   380     styleSheet := StyleSheet.
   379     styleSheet := StyleSheet.
   381 
   380 
   382     DefaultViewBackground := styleSheet colorAt:'pullDownMenu.viewBackground'.
   381     DefaultViewBackground := styleSheet colorAt:'pullDownMenu.viewBackground'.
   383     DefaultViewBackground isNil ifTrue:[
   382     DefaultViewBackground isNil ifTrue:[
   384         DefaultViewBackground := styleSheet colorAt:'menuView.background'.
   383 	DefaultViewBackground := styleSheet colorAt:'menuView.background'.
   385     ].
   384     ].
   386     DefaultForegroundColor := styleSheet colorAt:'pullDownMenu.foregroundColor'.
   385     DefaultForegroundColor := styleSheet colorAt:'pullDownMenu.foregroundColor'.
   387     DefaultForegroundColor isNil ifTrue:[
   386     DefaultForegroundColor isNil ifTrue:[
   388         DefaultForegroundColor := styleSheet colorAt:'menu.foregroundColor'.
   387 	DefaultForegroundColor := styleSheet colorAt:'menu.foregroundColor'.
   389     ].
   388     ].
   390     DefaultBackgroundColor := styleSheet colorAt:'pullDownMenu.backgroundColor'.
   389     DefaultBackgroundColor := styleSheet colorAt:'pullDownMenu.backgroundColor'.
   391     DefaultBackgroundColor isNil ifTrue:[
   390     DefaultBackgroundColor isNil ifTrue:[
   392         DefaultViewBackground notNil ifTrue:[
   391 	DefaultViewBackground notNil ifTrue:[
   393             DefaultBackgroundColor := DefaultViewBackground
   392 	    DefaultBackgroundColor := DefaultViewBackground
   394         ] ifFalse:[
   393 	] ifFalse:[
   395             DefaultBackgroundColor := styleSheet colorAt:'menu.backgroundColor'.
   394 	    DefaultBackgroundColor := styleSheet colorAt:'menu.backgroundColor'.
   396         ]
   395 	]
   397     ].
   396     ].
   398     DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenu.hilightForegroundColor'.
   397     DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenu.hilightForegroundColor'.
   399     DefaultHilightForegroundColor isNil ifTrue:[
   398     DefaultHilightForegroundColor isNil ifTrue:[
   400         DefaultHilightForegroundColor := styleSheet colorAt:'menu.hilightForegroundColor'.
   399 	DefaultHilightForegroundColor := styleSheet colorAt:'menu.hilightForegroundColor'.
   401     ].
   400     ].
   402     DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenu.hilightBackgroundColor'.
   401     DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenu.hilightBackgroundColor'.
   403     DefaultHilightBackgroundColor isNil ifTrue:[
   402     DefaultHilightBackgroundColor isNil ifTrue:[
   404         DefaultHilightBackgroundColor := styleSheet colorAt:'menu.hilightBackgroundColor'.
   403 	DefaultHilightBackgroundColor := styleSheet colorAt:'menu.hilightBackgroundColor'.
   405     ].
   404     ].
   406     DefaultHilightLevel := styleSheet at:'pullDownMenu.hilightLevel'.
   405     DefaultHilightLevel := styleSheet at:'pullDownMenu.hilightLevel'.
   407     DefaultHilightLevel isNil ifTrue:[
   406     DefaultHilightLevel isNil ifTrue:[
   408         DefaultHilightLevel := styleSheet at:'menu.hilightLevel' default:0.
   407 	DefaultHilightLevel := styleSheet at:'menu.hilightLevel' default:0.
   409     ].
   408     ].
   410     DefaultEdgeStyle := styleSheet at:'pullDownMenu.edgeStyle'.
   409     DefaultEdgeStyle := styleSheet at:'pullDownMenu.edgeStyle'.
   411     DefaultKeepMenu := styleSheet at:'pullDownMenu.keepMenu' default:false.
   410     DefaultToggleMode := styleSheet at:'pullDownMenu.toggleMode' default:#toggle.
   412     DefaultToggleKeep := styleSheet at:'pullDownMenu.toggleKeep' default:false.
       
   413     DefaultLevel := styleSheet at:'pullDownMenu.level' default:1.
   411     DefaultLevel := styleSheet at:'pullDownMenu.level' default:1.
   414     DefaultFont := styleSheet fontAt:'pullDownMenu.font'.
   412     DefaultFont := styleSheet fontAt:'pullDownMenu.font'.
   415     DefaultFont isNil ifTrue:[DefaultFont := styleSheet fontAt:'menu.font'].
   413     DefaultFont isNil ifTrue:[DefaultFont := styleSheet fontAt:'menu.font'].
   416     DefaultSeparatingLines := styleSheet at:'pullDownMenu.separatingLines' default:false.
   414     DefaultSeparatingLines := styleSheet at:'pullDownMenu.separatingLines' default:false.
   417 
   415 
   441      or #at:putLabels:selectors:..."
   439      or #at:putLabels:selectors:..."
   442 
   440 
   443     |idx|
   441     |idx|
   444 
   442 
   445     indexOrString isNil ifTrue:[
   443     indexOrString isNil ifTrue:[
   446         idx := titles size
   444 	idx := titles size
   447     ] ifFalse:[
   445     ] ifFalse:[
   448         idx := self indexOf:indexOrString.
   446 	idx := self indexOf:indexOrString.
   449     ].
   447     ].
   450 
   448 
   451     titles isNil ifTrue:[
   449     titles isNil ifTrue:[
   452         menus := Array with:nil.
   450 	menus := Array with:nil.
   453         titles := Array with:label.
   451 	titles := Array with:label.
   454         selectors := Array with:selector.
   452 	selectors := Array with:selector.
   455     ] ifFalse:[
   453     ] ifFalse:[
   456         menus := (menus copyTo:idx) , #(nil) , (menus copyFrom:idx+1).
   454 	menus := (menus copyTo:idx) , #(nil) , (menus copyFrom:idx+1).
   457         titles := ((titles copyTo:idx) copyWith:label) , (titles copyFrom:idx+1).
   455 	titles := ((titles copyTo:idx) copyWith:label) , (titles copyFrom:idx+1).
   458         selectors := ((selectors copyTo:idx) copyWith:selector) , (selectors copyFrom:idx+1).
   456 	selectors := ((selectors copyTo:idx) copyWith:selector) , (selectors copyFrom:idx+1).
   459     ].
   457     ].
   460 
   458 
   461     shown ifTrue:[
   459     shown ifTrue:[
   462         self redraw
   460 	self redraw
   463     ]
   461     ]
   464 
   462 
   465     "
   463     "
   466      |top m|
   464      |top m|
   467 
   465 
   470      m labels:#('file' 'edit').
   468      m labels:#('file' 'edit').
   471      m selectors:#(file #edit).
   469      m selectors:#(file #edit).
   472 
   470 
   473      m add:'help' selector:#help after:#file.
   471      m add:'help' selector:#help after:#file.
   474      m at:#help putMenu:(MenuView labels:#('foo' 'bar')
   472      m at:#help putMenu:(MenuView labels:#('foo' 'bar')
   475                                selectors:#(foo bar)
   473 			       selectors:#(foo bar)
   476                                 receiver:nil).
   474 				receiver:nil).
   477 
   475 
   478      top open
   476      top open
   479     "
   477     "
   480 
   478 
   481     "Modified: 5.7.1996 / 11:40:47 / cg"
   479     "Modified: 5.7.1996 / 11:40:47 / cg"
   488      or #at:putLabels:selectors:..."
   486      or #at:putLabels:selectors:..."
   489 
   487 
   490     |idx|
   488     |idx|
   491 
   489 
   492     indexOrString isNil ifTrue:[
   490     indexOrString isNil ifTrue:[
   493         idx := 1
   491 	idx := 1
   494     ] ifFalse:[
   492     ] ifFalse:[
   495         idx := self indexOf:indexOrString.
   493 	idx := self indexOf:indexOrString.
   496     ].
   494     ].
   497 
   495 
   498     titles isNil ifTrue:[
   496     titles isNil ifTrue:[
   499         menus := Array with:nil.
   497 	menus := Array with:nil.
   500         titles := Array with:label.
   498 	titles := Array with:label.
   501         selectors := Array with:selector.
   499 	selectors := Array with:selector.
   502     ] ifFalse:[
   500     ] ifFalse:[
   503         menus := (menus copyTo:idx-1) , #(nil) , (menus copyFrom:idx).
   501 	menus := (menus copyTo:idx-1) , #(nil) , (menus copyFrom:idx).
   504         titles := ((titles copyTo:idx-1) copyWith:label) , (titles copyFrom:idx).
   502 	titles := ((titles copyTo:idx-1) copyWith:label) , (titles copyFrom:idx).
   505         selectors := ((selectors copyTo:idx-1) copyWith:selector) , (selectors copyFrom:idx).
   503 	selectors := ((selectors copyTo:idx-1) copyWith:selector) , (selectors copyFrom:idx).
   506     ].
   504     ].
   507 
   505 
   508     shown ifTrue:[
   506     shown ifTrue:[
   509         self redraw
   507 	self redraw
   510     ]
   508     ]
   511 
   509 
   512     "
   510     "
   513      |top m|
   511      |top m|
   514 
   512 
   517      m labels:#('file' 'edit').
   515      m labels:#('file' 'edit').
   518      m selectors:#(file #edit).
   516      m selectors:#(file #edit).
   519 
   517 
   520      m add:'help' selector:#help before:#edit.
   518      m add:'help' selector:#help before:#edit.
   521      m at:#help putMenu:(MenuView labels:#('foo' 'bar')
   519      m at:#help putMenu:(MenuView labels:#('foo' 'bar')
   522                                selectors:#(foo bar)
   520 			       selectors:#(foo bar)
   523                                 receiver:nil).
   521 				receiver:nil).
   524 
   522 
   525      m add:'foo' selector:#foo before:nil.
   523      m add:'foo' selector:#foo before:nil.
   526      m at:#foo putMenu:(MenuView labels:#('foo1' 'foo2')
   524      m at:#foo putMenu:(MenuView labels:#('foo1' 'foo2')
   527                                selectors:#(foo1 foo2)
   525 			       selectors:#(foo1 foo2)
   528                                 receiver:nil).
   526 				receiver:nil).
   529 
   527 
   530      top open
   528      top open
   531     "
   529     "
   532 
   530 
   533     "Modified: 5.7.1996 / 11:40:55 / cg"
   531     "Modified: 5.7.1996 / 11:40:55 / cg"
   555     "create and set the menu under the title, aString"
   553     "create and set the menu under the title, aString"
   556 
   554 
   557     |menuView|
   555     |menuView|
   558 
   556 
   559     menuView := MenuView labels:labels
   557     menuView := MenuView labels:labels
   560                       selectors:selectors
   558 		      selectors:selectors
   561                    accelerators:shorties
   559 		   accelerators:shorties
   562                            args:args
   560 			   args:args
   563                        receiver:anObject
   561 		       receiver:anObject
   564                             for:self.
   562 			    for:self.
   565     self at:aString putMenu:menuView
   563     self at:aString putMenu:menuView
   566 
   564 
   567     "Created: 5.6.1996 / 16:51:48 / cg"
   565     "Created: 5.6.1996 / 16:51:48 / cg"
   568 !
   566 !
   569 
   567 
   602 
   600 
   603     |index|
   601     |index|
   604 
   602 
   605     index := self indexOf:aString.
   603     index := self indexOf:aString.
   606     (index == 0) ifTrue:[
   604     (index == 0) ifTrue:[
   607         self error:'no such menu entry'.
   605 	self error:'no such menu entry'.
   608         ^ nil
   606 	^ nil
   609     ].
   607     ].
   610 
   608 
   611     aMenu container:(self superView).
   609     aMenu container:(self superView).
   612     aMenu beInvisible.
   610     aMenu beInvisible.
   613     menus at:index put:aMenu.
   611     menus at:index put:aMenu.
   630     numberOfLabels := titleArray size.
   628     numberOfLabels := titleArray size.
   631     menus := Array new:numberOfLabels.
   629     menus := Array new:numberOfLabels.
   632     titles := Array new:numberOfLabels.
   630     titles := Array new:numberOfLabels.
   633 
   631 
   634     titleArray keysAndValuesDo:[:index :entry |
   632     titleArray keysAndValuesDo:[:index :entry |
   635         |e|
   633 	|e|
   636 
   634 
   637         entry isImage ifTrue:[
   635 	entry isImage ifTrue:[
   638             e := entry on:device
   636 	    e := entry on:device
   639         ] ifFalse:[
   637 	] ifFalse:[
   640             e := entry printString
   638 	    e := entry printString
   641         ].
   639 	].
   642         titles at:index put:e
   640 	titles at:index put:e
   643     ].
   641     ].
   644     shown ifTrue:[
   642     shown ifTrue:[
   645         self invalidate "/ clear; redraw
   643 	self invalidate "/ clear; redraw
   646     ]
   644     ]
   647 
   645 
   648     "Modified: 29.5.1996 / 16:21:00 / cg"
   646     "Modified: 29.5.1996 / 16:21:00 / cg"
   649 !
   647 !
   650 
   648 
   701     menus removeIndex:idx.
   699     menus removeIndex:idx.
   702     titles removeIndex:idx.
   700     titles removeIndex:idx.
   703     selectors removeIndex:idx.
   701     selectors removeIndex:idx.
   704 
   702 
   705     shown ifTrue:[
   703     shown ifTrue:[
   706         self clear.
   704 	self clear.
   707         self redraw
   705 	self redraw
   708     ]
   706     ]
   709 
   707 
   710     "
   708     "
   711      |top m|
   709      |top m|
   712 
   710 
   717      top open.
   715      top open.
   718 
   716 
   719      Delay waitForSeconds:3.
   717      Delay waitForSeconds:3.
   720      m add:'help' selector:#help after:#file.
   718      m add:'help' selector:#help after:#file.
   721      m at:#help putMenu:(MenuView labels:#('foo' 'bar')
   719      m at:#help putMenu:(MenuView labels:#('foo' 'bar')
   722                                selectors:#(foo bar)
   720 			       selectors:#(foo bar)
   723                                 receiver:nil).
   721 				receiver:nil).
   724 
   722 
   725      Delay waitForSeconds:3.
   723      Delay waitForSeconds:3.
   726      m remove:'help'
   724      m remove:'help'
   727     "
   725     "
   728 
   726 
   781     |index newActions|
   779     |index newActions|
   782 
   780 
   783     index := self indexOf:stringOrNumber.
   781     index := self indexOf:stringOrNumber.
   784     (index == 0) ifTrue:[^ nil].
   782     (index == 0) ifTrue:[^ nil].
   785     actions size < index ifTrue:[
   783     actions size < index ifTrue:[
   786         newActions := Array new:index.
   784 	newActions := Array new:index.
   787         newActions replaceFrom:1 to:actions size with:actions.
   785 	newActions replaceFrom:1 to:actions size with:actions.
   788         actions := newActions
   786 	actions := newActions
   789     ].
   787     ].
   790     actions at:index put:aBlock
   788     actions at:index put:aBlock
   791 
   789 
   792     "Modified: 24.3.1996 / 17:09:56 / cg"
   790     "Modified: 24.3.1996 / 17:09:56 / cg"
   793     "Created: 17.4.1996 / 20:52:13 / cg"
   791     "Created: 17.4.1996 / 20:52:13 / cg"
   807     "set the menus font.
   805     "set the menus font.
   808      adjusts menu-origins when font changes.
   806      adjusts menu-origins when font changes.
   809      You should not use this method; instead leave the value as
   807      You should not use this method; instead leave the value as
   810      defined in the styleSheet.
   808      defined in the styleSheet.
   811      CAVEAT: with the addition of Text objects,
   809      CAVEAT: with the addition of Text objects,
   812              this method is going to be obsoleted by a textStyle
   810 	     this method is going to be obsoleted by a textStyle
   813              method, which allows specific control over
   811 	     method, which allows specific control over
   814              normalFont/boldFont/italicFont parameters."
   812 	     normalFont/boldFont/italicFont parameters."
   815 
   813 
   816     aFont ~~ font ifTrue:[
   814     aFont ~~ font ifTrue:[
   817         super font:(aFont on:device).
   815 	super font:(aFont on:device).
   818         self height:(font height + (font descent * 2)).
   816 	self height:(font height + (font descent * 2)).
   819         shown ifTrue:[
   817 	shown ifTrue:[
   820             self setMenuOrigins
   818 	    self setMenuOrigins
   821         ]
   819 	]
   822     ]
   820     ]
   823 
   821 
   824     "Modified: 22.5.1996 / 12:37:04 / cg"
   822     "Modified: 22.5.1996 / 12:37:04 / cg"
   825 !
   823 !
   826 
   824 
   837      You should not use this method; instead leave the value as
   835      You should not use this method; instead leave the value as
   838      defined in the styleSheet."
   836      defined in the styleSheet."
   839 
   837 
   840     showSeparatingLines := aBoolean.
   838     showSeparatingLines := aBoolean.
   841     shown ifTrue:[
   839     shown ifTrue:[
   842         self setMenuOrigins.
   840 	self setMenuOrigins.
   843         self invalidate
   841 	self invalidate
   844     ]
   842     ]
   845 
   843 
   846     "Modified: 29.5.1996 / 16:21:06 / cg"
   844     "Modified: 29.5.1996 / 16:21:06 / cg"
   847 ! !
   845 ! !
   848 
   846 
   858 
   856 
   859     menu   := Menu new.
   857     menu   := Menu new.
   860     values := aView selectors.
   858     values := aView selectors.
   861 
   859 
   862     aView labels keysAndValuesDo:[:anIndex :aLabel|
   860     aView labels keysAndValuesDo:[:anIndex :aLabel|
   863         item := MenuItem labeled:(aLabel printString).
   861 	item := MenuItem labeled:(aLabel printString).
   864         aLabel isImage ifTrue:[
   862 	aLabel isImage ifTrue:[
   865             rcv := ResourceRetriever new.
   863 	    rcv := ResourceRetriever new.
   866             rcv className:#MenuEditor.
   864 	    rcv className:#MenuEditor.
   867             rcv selector:#iconUnknown.
   865 	    rcv selector:#iconUnknown.
   868             item labelImage:rcv.
   866 	    item labelImage:rcv.
   869         ] ifFalse:[
   867 	] ifFalse:[
   870             aView ~~ self ifTrue:[
   868 	    aView ~~ self ifTrue:[
   871                 rcv := aView checkToggleAt:anIndex.
   869 		rcv := aView checkToggleAt:anIndex.
   872                 rcv notNil ifTrue:[
   870 		rcv notNil ifTrue:[
   873                     item indication:rcv
   871 		    item indication:rcv
   874                 ]
   872 		]
   875             ]
   873 	    ]
   876         ].
   874 	].
   877 
   875 
   878         subM := aView subMenuAt:anIndex.
   876 	subM := aView subMenuAt:anIndex.
   879 
   877 
   880         subM notNil ifTrue:[
   878 	subM notNil ifTrue:[
   881             item submenu:(self asMenu:subM)
   879 	    item submenu:(self asMenu:subM)
   882         ].
   880 	].
   883         menu addItem:item value:(values at:anIndex).
   881 	menu addItem:item value:(values at:anIndex).
   884     ].
   882     ].
   885   ^ menu
   883   ^ menu
   886 
   884 
   887 
   885 
   888 ! !
   886 ! !
   899 
   897 
   900 drawTitle:stringOrImage x:x0 selected:selected
   898 drawTitle:stringOrImage x:x0 selected:selected
   901     |y w x wSpace fg bg map|
   899     |y w x wSpace fg bg map|
   902 
   900 
   903     selected ifTrue:[
   901     selected ifTrue:[
   904         fg := activeFgColor.
   902 	fg := activeFgColor.
   905         bg := activeBgColor
   903 	bg := activeBgColor
   906     ] ifFalse:[
   904     ] ifFalse:[
   907         fg := fgColor.
   905 	fg := fgColor.
   908         bg := bgColor
   906 	bg := bgColor
   909     ].
   907     ].
   910 
   908 
   911     wSpace := font widthOf:' '.
   909     wSpace := font widthOf:' '.
   912     x := x0.
   910     x := x0.
   913     stringOrImage isString ifTrue:[
   911     stringOrImage isString ifTrue:[
   914         y := ((height - (font height)) // 2) + (font ascent) "+ topMargin".
   912 	y := ((height - (font height)) // 2) + (font ascent) "+ topMargin".
   915         w := font widthOf:stringOrImage.
   913 	w := font widthOf:stringOrImage.
   916     ] ifFalse:[
   914     ] ifFalse:[
   917         y := ((height - stringOrImage height) // 2) max:0.
   915 	y := ((height - stringOrImage height) // 2) max:0.
   918         w := stringOrImage width
   916 	w := stringOrImage width
   919     ].
   917     ].
   920     w := w + (wSpace * 2).
   918     w := w + (wSpace * 2).
   921 
   919 
   922     self paint:bg.
   920     self paint:bg.
   923     self fillRectangleX:x y:0 width:w height:height.
   921     self fillRectangleX:x y:0 width:w height:height.
   924 
   922 
   925     self is3D ifTrue:[
   923     self is3D ifTrue:[
   926         self drawEdgesForX:x y:0
   924 	self drawEdgesForX:x y:0
   927                      width:w
   925 		     width:w
   928                     height:height
   926 		    height:height
   929                      level:(selected ifTrue:[onLevel] ifFalse:[offLevel])
   927 		     level:(selected ifTrue:[onLevel] ifFalse:[offLevel])
   930     ].
   928     ].
   931     self paint:fg on:bg.
   929     self paint:fg on:bg.
   932     x := x + wSpace.
   930     x := x + wSpace.
   933     stringOrImage isString ifTrue:[
   931     stringOrImage isString ifTrue:[
   934         self displayOpaqueString:stringOrImage x:x y:y
   932 	self displayOpaqueString:stringOrImage x:x y:y
   935     ] ifFalse:[
   933     ] ifFalse:[
   936         stringOrImage isImageOrForm ifTrue:[
   934 	stringOrImage isImageOrForm ifTrue:[
   937             stringOrImage depth == 1 ifTrue:[
   935 	    stringOrImage depth == 1 ifTrue:[
   938                 (map := stringOrImage colorMap) notNil ifTrue:[
   936 		(map := stringOrImage colorMap) notNil ifTrue:[
   939                     map at:1 put:((map at:1) on:device).
   937 		    map at:1 put:((map at:1) on:device).
   940                     map at:2 put:((map at:2) on:device).
   938 		    map at:2 put:((map at:2) on:device).
   941 
   939 
   942                     self paint:(map at:2) on:(map at:1).
   940 		    self paint:(map at:2) on:(map at:1).
   943                     self displayOpaqueForm:stringOrImage x:x y:y.
   941 		    self displayOpaqueForm:stringOrImage x:x y:y.
   944                     ^ self
   942 		    ^ self
   945                 ]
   943 		]
   946             ].
   944 	    ].
   947             self displayForm:stringOrImage x:x y:y
   945 	    self displayForm:stringOrImage x:x y:y
   948         ] ifFalse:[
   946 	] ifFalse:[
   949             stringOrImage displayOn:self x:x y:y
   947 	    stringOrImage displayOn:self x:x y:y
   950         ]
   948 	]
   951     ]
   949     ]
   952 
   950 
   953     "Modified: 14.1.1997 / 00:06:07 / cg"
   951     "Modified: 14.1.1997 / 00:06:07 / cg"
   954 !
   952 !
   955 
   953 
   969     wSpace := (font widthOf:' ').
   967     wSpace := (font widthOf:' ').
   970     x := 0.
   968     x := 0.
   971     y := height "- 1".
   969     y := height "- 1".
   972     index := 1.
   970     index := 1.
   973     titles do:[:title |
   971     titles do:[:title |
   974         self drawTitle:title x:x selected:(index == activeMenuNumber).
   972 	self drawTitle:title x:x selected:(index == activeMenuNumber).
   975 
   973 
   976         title isString ifTrue:[
   974 	title isString ifTrue:[
   977             x := x + (font widthOf:title).
   975 	    x := x + (font widthOf:title).
   978         ] ifFalse:[
   976 	] ifFalse:[
   979             x := x + title width
   977 	    x := x + title width
   980         ].
   978 	].
   981         x := x + wSpace + wSpace.
   979 	x := x + wSpace + wSpace.
   982         showSeparatingLines ifTrue:[
   980 	showSeparatingLines ifTrue:[
   983             self is3D ifTrue:[
   981 	    self is3D ifTrue:[
   984                 self paint:shadowColor.
   982 		self paint:shadowColor.
   985                 self displayLineFromX:x y:0 toX:x y:y.
   983 		self displayLineFromX:x y:0 toX:x y:y.
   986                 x := x + 1.
   984 		x := x + 1.
   987                 clr := lightColor.
   985 		clr := lightColor.
   988             ] ifFalse:[
   986 	    ] ifFalse:[
   989                 clr := fgColor.
   987 		clr := fgColor.
   990             ].
   988 	    ].
   991             self paint:clr.
   989 	    self paint:clr.
   992             self displayLineFromX:x y:0 toX:x y:y.
   990 	    self displayLineFromX:x y:0 toX:x y:y.
   993             x := x + 1
   991 	    x := x + 1
   994         ].
   992 	].
   995         index := index + 1
   993 	index := index + 1
   996     ]
   994     ]
   997 
   995 
   998     "Modified: 14.1.1997 / 00:06:22 / cg"
   996     "Modified: 14.1.1997 / 00:06:22 / cg"
   999 !
   997 !
  1000 
   998 
  1005 !PullDownMenu methodsFor:'event handling'!
  1003 !PullDownMenu methodsFor:'event handling'!
  1006 
  1004 
  1007 buttonMotion:state x:x y:y
  1005 buttonMotion:state x:x y:y
  1008     |titleIndex activeMenu activeLeft activeTop|
  1006     |titleIndex activeMenu activeLeft activeTop|
  1009 
  1007 
  1010     state == 0 ifTrue:[^ self].
  1008     state == 0 ifTrue:[
       
  1009 	self hideActiveMenu.
       
  1010 	^ self
       
  1011     ].
       
  1012 
       
  1013     activeMenuNumber isNil ifTrue:[^ self].
  1011 
  1014 
  1012     activeMenuNumber notNil ifTrue:[
  1015     activeMenuNumber notNil ifTrue:[
  1013         activeMenu := menus at:activeMenuNumber.
  1016 	activeMenu := menus at:activeMenuNumber.
  1014     ].
  1017     ].
  1015 
  1018 
  1016     (y < height) ifTrue:[
  1019     (y < height) ifTrue:[
  1017         "moving around in title line"
  1020 	"moving around in title line"
  1018         activeMenu notNil ifTrue:[
  1021 	activeMenu notNil ifTrue:[
  1019             activeMenu setSelection:nil
  1022 	    activeMenu setSelection:nil
  1020         ].
  1023 	].
  1021         titleIndex := self titleIndexForX:x.
  1024 	titleIndex := self titleIndexForX:x.
  1022         titleIndex notNil ifTrue:[
  1025 	titleIndex notNil ifTrue:[
  1023             (titleIndex ~~ activeMenuNumber) ifTrue:[
  1026 	    (titleIndex ~~ activeMenuNumber) ifTrue:[
  1024                 self pullMenu:titleIndex
  1027 		self pullMenu:titleIndex
  1025             ]
  1028 	    ]
  1026         ] ifFalse:[
  1029 	] ifFalse:[
  1027             self hideActiveMenu
  1030 	    self hideActiveMenu
  1028         ]
  1031 	]
  1029     ] ifFalse:[
  1032     ] ifFalse:[
  1030         "moving around below"
  1033 	"moving around below"
  1031         activeMenu isNil ifTrue:[^self].
  1034 	activeMenu isNil ifTrue:[^self].
  1032         activeLeft := activeMenu left.
  1035 	activeLeft := activeMenu left.
  1033         (x between:activeLeft and:(activeMenu right)) ifTrue:[
  1036 	(x between:activeLeft and:(activeMenu right)) ifTrue:[
  1034             activeTop := activeMenu top.
  1037 	    activeTop := activeMenu top.
  1035             (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1038 	    (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1036                 "moving around in menu"
  1039 		"moving around in menu"
  1037                 activeMenu buttonMotion:state
  1040 		activeMenu buttonMotion:state
  1038                                       x:(x - activeLeft)
  1041 				      x:(x - activeLeft)
  1039                                       y:(y - activeTop).
  1042 				      y:(y - activeTop).
  1040                 ^ self
  1043 		^ self
  1041             ]
  1044 	    ]
  1042         ].
  1045 	].
  1043         "moved outside menu"
  1046 	"moved outside menu"
  1044         activeMenu setSelection:nil
  1047 	activeMenu setSelection:nil
  1045     ]
  1048     ]
  1046 
  1049 
  1047     "Modified: 25.5.1996 / 12:28:32 / cg"
  1050     "Modified: 25.5.1996 / 12:28:32 / cg"
  1048 !
  1051 !
  1049 
  1052 
  1050 buttonPress:button x:x y:y
  1053 buttonPress:button x:x y:y
  1051     |titleIndex activeMenu activeLeft activeTop m|
  1054     |titleIndex activeMenu activeLeft activeTop m|
  1052 
  1055 
  1053     device ungrabPointer.
  1056     device ungrabPointer.
  1054 device ungrabKeyboard.
  1057     device ungrabKeyboard.
  1055 
  1058 
  1056     (y between:0 and:height) ifTrue:[
  1059     (y between:0 and:height) ifTrue:[
  1057         titleIndex := self titleIndexForX:x.
  1060 	titleIndex := self titleIndexForX:x.
  1058     ].
  1061     ].
  1059 
  1062 
  1060     "
  1063     "
  1061      now, titleIndex is non-nil if pressed within myself
  1064      now, titleIndex is non-nil if pressed within myself
  1062     "
  1065     "
  1063     (titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
  1066     (titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
  1064         m := self pullMenu:titleIndex.
  1067 	"/ pressed on another item
  1065         (keepMenu and:[m notNil]) ifTrue:[
  1068 	m := self pullMenu:titleIndex.
  1066             device grabPointerInView:self.
  1069 	(toggleMode == #toggle) ifTrue:[
  1067 device grabKeyboardInView:self.
  1070 	    device grabPointerInView:self.
       
  1071 	    device grabKeyboardInView:self.
  1068 "/            self cursor:Cursor upRightArrow
  1072 "/            self cursor:Cursor upRightArrow
  1069         ]
  1073 	]
  1070     ] ifFalse:[
  1074     ] ifFalse:[
  1071         (keepMenu and:[toggleKeep not]) ifTrue:[
  1075 	titleIndex == activeMenuNumber ifTrue:[
  1072             titleIndex == activeMenuNumber ifTrue:[
  1076 	    "/ pressed on same item
  1073                 "same pressed again ... stay"
  1077 	    (toggleMode ~~ #toggle) ifTrue:[
  1074                 titleIndex notNil ifTrue:[
  1078 		"same pressed again ... stay"
  1075                     device grabPointerInView:self.
  1079 		titleIndex notNil ifTrue:[
  1076 device grabKeyboardInView:self.
  1080 		    device grabPointerInView:self.
  1077                 ].
  1081 		    device grabKeyboardInView:self.
  1078                 ^ self
  1082 		].
  1079             ].
  1083 	    ] ifFalse:[
  1080             "moving around below"
  1084 		self hideActiveMenu.
  1081             activeMenuNumber isNil ifTrue:[^self].
  1085 	    ].
  1082             activeMenu := menus at:activeMenuNumber.
  1086 	    ^ self
  1083             activeLeft := activeMenu left.
  1087 	].
  1084             (x between:activeLeft and:(activeMenu right)) ifTrue:[
  1088 
  1085                 activeTop := activeMenu top.
  1089 	"/ pressed outside
  1086                 (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1090 
  1087                     "moving around in menu"
  1091 	activeMenuNumber isNil ifTrue:[^self].
  1088                     activeMenu buttonPress:button
  1092 
  1089                                          x:(x - activeLeft)
  1093 	activeMenu := menus at:activeMenuNumber.
  1090                                          y:(y - activeTop).
  1094 	activeLeft := activeMenu left.
  1091                     ^ self
  1095 	(x between:activeLeft and:(activeMenu right)) ifTrue:[
  1092                 ]
  1096 	    activeTop := activeMenu top.
  1093             ].
  1097 	    (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1094         ].
  1098 		"/ pressed inside currently pulled menu
  1095         self hideActiveMenu
  1099 		activeMenu buttonPress:button x:(x - activeLeft) y:(y - activeTop).
       
  1100 		^ self
       
  1101 	    ].
       
  1102 	].
       
  1103 
       
  1104 	"/ somewhere else
       
  1105 	self hideActiveMenu
  1096     ]
  1106     ]
  1097 
  1107 
  1098     "Modified: 6.3.1996 / 17:14:16 / cg"
  1108     "Modified: 6.3.1996 / 17:14:16 / cg"
  1099 !
  1109 !
  1100 
  1110 
  1104     activeMenuNumber isNil ifTrue:[^self].
  1114     activeMenuNumber isNil ifTrue:[^self].
  1105     activeMenu := menus at:activeMenuNumber.
  1115     activeMenu := menus at:activeMenuNumber.
  1106 
  1116 
  1107     hideMenu := false.
  1117     hideMenu := false.
  1108     (y >= height) ifTrue:[
  1118     (y >= height) ifTrue:[
  1109         "release below title-line"
  1119 	"release below title-line"
  1110         activeLeft := activeMenu left.
  1120 	activeLeft := activeMenu left.
  1111         "
  1121 	"
  1112          released in a submenu ?
  1122 	 released in a submenu ?
  1113         "
  1123 	"
  1114         (x between:activeLeft and:(activeMenu right)) ifTrue:[
  1124 	(x between:activeLeft and:(activeMenu right)) ifTrue:[
  1115             activeTop := activeMenu top.
  1125 	    activeTop := activeMenu top.
  1116             (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1126 	    (y between:activeTop and:(activeMenu bottom)) ifTrue:[
  1117                 "release in menu"
  1127 		"release in menu"
  1118                 self hideActiveMenu.   
  1128 		self hideActiveMenu.   
  1119                 activeMenu buttonRelease:button
  1129 		activeMenu buttonRelease:button
  1120                                        x:(x - activeLeft)
  1130 				       x:(x - activeLeft)
  1121                                        y:(y - activeTop).
  1131 				       y:(y - activeTop).
  1122                 ^ self
  1132 		^ self
  1123             ]
  1133 	    ]
  1124         ].
  1134 	].
  1125         hideMenu := true.
  1135 	hideMenu := true.
  1126     ] ifFalse:[
  1136     ] ifFalse:[
  1127         y < 0 ifTrue:[
  1137 	y < 0 ifTrue:[
  1128             hideMenu := true
  1138 	    hideMenu := true
  1129         ] ifFalse:[
  1139 	] ifFalse:[
  1130             activeMenu isNil ifTrue:[
  1140 	    activeMenu isNil ifTrue:[
  1131                 self performSelectedAction.
  1141 		self performSelectedAction.
  1132                 hideMenu := true.
  1142 		hideMenu := true.
  1133             ] ifFalse:[
  1143 	    ] ifFalse:[
  1134                 keepMenu ifFalse:[   
  1144 		(toggleMode == #toggle) ifFalse:[   
  1135                     hideMenu := true
  1145 		    hideMenu := true
  1136                 ]
  1146 		]
  1137             ]
  1147 	    ]
  1138         ]
  1148 	]
  1139     ].                  
  1149     ].                  
  1140     hideMenu ifTrue:[
  1150     hideMenu ifTrue:[
  1141        self hideActiveMenu.
  1151        self hideActiveMenu.
  1142     ]
  1152     ]
  1143 
  1153 
  1154      handle CursorLeft/Right for non-mouse operation
  1164      handle CursorLeft/Right for non-mouse operation
  1155      (for example, if it has the explicit focus)
  1165      (for example, if it has the explicit focus)
  1156      These will pull the previous/next menu
  1166      These will pull the previous/next menu
  1157     "
  1167     "
  1158     ((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[
  1168     ((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[
  1159         activeMenuNumber isNil ifTrue:[
  1169 	activeMenuNumber isNil ifTrue:[
  1160             index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size].
  1170 	    index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size].
  1161         ] ifFalse:[
  1171 	] ifFalse:[
  1162             (key == #CursorRight) ifTrue:[
  1172 	    (key == #CursorRight) ifTrue:[
  1163                 index := activeMenuNumber+1
  1173 		"/ if its a cursor-right, and the current item
  1164             ] ifFalse:[
  1174 		"/ has a submenu, then pop up the submenu
  1165                 index := activeMenuNumber-1
  1175 		m := menus at:activeMenuNumber.
  1166             ].
  1176 		m notNil ifTrue:[
  1167             index == 0 ifTrue:[index := menus size]
  1177 		    m selectedItemHasSubmenu ifTrue:[
  1168             ifFalse:[
  1178 			m showSubmenu:(m selection).
  1169                 index > menus size ifTrue:[index := 1]
  1179 			^ self.
  1170             ]
  1180 		    ].
  1171         ].
  1181 		].
  1172         self pullMenu:index.
  1182 	    ].
  1173         ^ self
  1183 
       
  1184 	    (key == #CursorRight) ifTrue:[
       
  1185 		index := activeMenuNumber+1
       
  1186 	    ] ifFalse:[
       
  1187 		index := activeMenuNumber-1
       
  1188 	    ].
       
  1189 	    index == 0 ifTrue:[index := menus size]
       
  1190 	    ifFalse:[
       
  1191 		index > menus size ifTrue:[index := 1]
       
  1192 	    ]
       
  1193 	].
       
  1194 	self pullMenu:index.
       
  1195 	^ self
  1174     ].
  1196     ].
  1175 
  1197 
  1176 "/    activeMenuNumber isNil ifTrue:[
  1198 "/    activeMenuNumber isNil ifTrue:[
  1177         "/
  1199 	"/
  1178         "/ find an item starting with that alpha-key
  1200 	"/ find an item starting with that alpha-key
  1179         "/
  1201 	"/
  1180         key isCharacter ifTrue:[
  1202 	key isCharacter ifTrue:[
  1181             (key isLetter) ifTrue:[
  1203 	    (key isLetter) ifTrue:[
  1182                 activeMenuNumber isNil ifTrue:[
  1204 		activeMenuNumber isNil ifTrue:[
  1183                     startIndex := 1.
  1205 		    startIndex := 1.
  1184                 ] ifFalse:[
  1206 		] ifFalse:[
  1185                     startIndex := activeMenuNumber + 1
  1207 		    startIndex := activeMenuNumber + 1
  1186                 ].
  1208 		].
  1187                 index := titles 
  1209 		index := titles 
  1188                             findFirst:[:item | 
  1210 			    findFirst:[:item | 
  1189                                             item isString
  1211 					    item isString
  1190                                             and:[(item startsWith:key asUppercase)
  1212 					    and:[(item startsWith:key asUppercase)
  1191                                                  or:[item startsWith:key asLowercase]]]
  1213 						 or:[item startsWith:key asLowercase]]]
  1192                             startingAt:startIndex.
  1214 			    startingAt:startIndex.
  1193 
  1215 
  1194                 (index == 0 and:[startIndex ~~ 1]) ifTrue:[
  1216 		(index == 0 and:[startIndex ~~ 1]) ifTrue:[
  1195                     index := titles 
  1217 		    index := titles 
  1196                                 findFirst:[:item | 
  1218 				findFirst:[:item | 
  1197                                                 item isString
  1219 						item isString
  1198                                                 and:[(item startsWith:key asUppercase)
  1220 						and:[(item startsWith:key asUppercase)
  1199                                                      or:[item startsWith:key asLowercase]]]
  1221 						     or:[item startsWith:key asLowercase]]]
  1200                                 startingAt:1.
  1222 				startingAt:1.
  1201                 ].
  1223 		].
  1202 
  1224 
  1203                 index ~~ 0 ifTrue:[
  1225 		index ~~ 0 ifTrue:[
  1204                     self pullMenu:index.
  1226 		    self pullMenu:index.
  1205                 ].
  1227 		].
  1206                 ^ self
  1228 		^ self
  1207             ]
  1229 	    ]
  1208         ].
  1230 	].
  1209 "/    ].
  1231 "/    ].
  1210 
  1232 
  1211     activeMenuNumber isNil ifTrue:[
  1233     activeMenuNumber isNil ifTrue:[
  1212         ^ super keyPress:key x:x y:y
  1234 	^ super keyPress:key x:x y:y
  1213     ].
  1235     ].
  1214 
  1236 
  1215     "
  1237     "
  1216      Return, space or the (virtual) MenuSelect key trigger
  1238      Return, space or the (virtual) MenuSelect key trigger
  1217      a menu entry (for non-submenu entries).
  1239      a menu entry (for non-submenu entries).
  1218      Otherwise, if we have a submenu open,
  1240      Otherwise, if we have a submenu open,
  1219      pass the key on to it ...
  1241      pass the key on to it ...
  1220     "
  1242     "
  1221     m := menus at:activeMenuNumber.
  1243     m := menus at:activeMenuNumber.
  1222     m isNil ifTrue:[
  1244     m isNil ifTrue:[
  1223         (key == #Return 
  1245 	(key == #Return 
  1224         or:[key == #MenuSelect
  1246 	or:[key == #MenuSelect
  1225         or:[key == Character space]]) ifTrue:[
  1247 	or:[key == Character space]]) ifTrue:[
  1226             self performSelectedAction.
  1248 	    self performSelectedAction.
  1227         ].
  1249 	].
  1228     ] ifFalse:[
  1250     ] ifFalse:[
  1229         m keyPress:key x:0 y:0.
  1251 	m keyPress:key x:0 y:0.
  1230     ].
  1252     ].
  1231 
  1253 
  1232     "Modified: 25.2.1997 / 23:38:15 / cg"
  1254     "Modified: 25.2.1997 / 23:38:15 / cg"
  1233 !
  1255 !
  1234 
  1256 
  1235 showNoFocus:explicit
  1257 showNoFocus:explicit
  1236     "when stepping focus, hide any active menu"
  1258     "when stepping focus, hide any active menu"
  1237 
  1259 
  1238     explicit ifTrue:[
  1260     explicit ifTrue:[
  1239         self hideActiveMenu.
  1261 	self hideActiveMenu.
  1240         super showNoFocus:explicit
  1262 	super showNoFocus:explicit
  1241     ]
  1263     ]
  1242 
  1264 
  1243     "Modified: 25.2.1997 / 23:31:38 / cg"
  1265     "Modified: 25.2.1997 / 23:31:38 / cg"
  1244 ! !
  1266 ! !
  1245 
  1267 
  1250 
  1272 
  1251     self hideActiveMenu.
  1273     self hideActiveMenu.
  1252 !
  1274 !
  1253 
  1275 
  1254 hideActiveMenu
  1276 hideActiveMenu
  1255     "hide currently active menu - release grab if there is any grab (keepMenu)"
  1277     "hide currently active menu - release grab if there is any grab"
  1256 
  1278 
  1257     ^ self hideActiveMenuRelease:true
  1279     ^ self hideActiveMenuRelease:true
  1258 !
  1280 !
  1259 
  1281 
  1260 hideActiveMenuRelease:aBoolean
  1282 hideActiveMenuRelease:aBoolean
  1261     "hide currently active menu - release grab if aBoolean is true
  1283     "hide currently active menu - release grab if aBoolean is true
  1262      and a grab was set (keepMenu)"
  1284      and a grab was set"
  1263 
  1285 
  1264     |m|
  1286     |m|
  1265 
  1287 
  1266     activeMenuNumber notNil ifTrue:[
  1288     activeMenuNumber notNil ifTrue:[
  1267         (m := menus at:activeMenuNumber) notNil ifTrue:[
  1289 	(m := menus at:activeMenuNumber) notNil ifTrue:[
  1268             m beInvisible.
  1290 	    m beInvisible.
  1269         ].
  1291 	].
  1270         self unHighlightActiveTitle.
  1292 	self unHighlightActiveTitle.
  1271         activeMenuNumber := nil
  1293 	activeMenuNumber := nil
  1272     ].
  1294     ].
  1273     aBoolean ifTrue:[
  1295     aBoolean ifTrue:[
  1274         device ungrabKeyboard.
  1296 	device ungrabKeyboard.
  1275         device ungrabPointer. 
  1297 	device ungrabPointer. 
  1276 "/        self cursor:Cursor normal
  1298 "/        self cursor:Cursor normal
  1277     ].
  1299     ].
  1278 
  1300 
  1279     "Modified: 6.3.1996 / 17:14:21 / cg"
  1301     "Modified: 6.3.1996 / 17:14:21 / cg"
  1280 !
  1302 !
  1289     activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
  1311     activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
  1290     activeMenuNumber := aNumber.
  1312     activeMenuNumber := aNumber.
  1291     subMenu := menus at:aNumber.
  1313     subMenu := menus at:aNumber.
  1292 
  1314 
  1293     raiseTopWhenActivated ifTrue:[
  1315     raiseTopWhenActivated ifTrue:[
  1294         self topView raise.
  1316 	self topView raise.
  1295     ].
  1317     ].
  1296 
  1318 
  1297     (activeMenuNumber notNil 
  1319     (activeMenuNumber notNil 
  1298     and:[
  1320     and:[
  1299          subMenu notNil
  1321 	 subMenu notNil
  1300          or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[
  1322 	 or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[
  1301             self highlightActiveTitle.
  1323 	    self highlightActiveTitle.
  1302          ].
  1324 	 ].
  1303 
  1325 
  1304     subMenu notNil ifTrue:[
  1326     subMenu notNil ifTrue:[
  1305         subMenu origin:((left + (self titleLenUpTo:aNumber)) 
  1327 	subMenu origin:((left + (self titleLenUpTo:aNumber)) 
  1306                        @
  1328 		       @
  1307                        (posY := height + subMenu borderWidth)).
  1329 		       (posY := height + subMenu borderWidth)).
  1308         subMenu hiddenOnRealize:false.
  1330 	subMenu hiddenOnRealize:false.
  1309         subMenu setSelection:nil.
  1331 	subMenu setSelection:nil.
  1310         subMenu create.
  1332 	subMenu create.
  1311         subMenu saveUnder:true.
  1333 	subMenu saveUnder:true.
  1312         subMenu superMenu:self.
  1334 	subMenu superMenu:self.
  1313 
  1335 
  1314         subMenu right > (r := self right) ifTrue:[
  1336 	subMenu right > (r := self right) ifTrue:[
  1315             subMenu origin:((r - subMenu width) @ posY).
  1337 	    subMenu origin:((r - subMenu width) @ posY).
  1316         ].
  1338 	].
  1317         subMenu raise show.
  1339 	subMenu raise show.
  1318 
  1340 
  1319         (styleSheet at:#'pullDownMenu.autoselectFirst') == true ifTrue:[
  1341 	(styleSheet at:#'pullDownMenu.autoselectFirst') == true ifTrue:[
  1320             subMenu setSelection:1
  1342 	    subMenu setSelection:1
  1321         ]
  1343 	]
  1322     ].
  1344     ].
  1323     ^ subMenu
  1345     ^ subMenu
  1324 
  1346 
  1325     "Modified: / 26.10.1997 / 17:04:00 / cg"
  1347     "Modified: / 26.10.1997 / 17:04:00 / cg"
  1326 !
  1348 !
  1327 
  1349 
  1328 regainControl
  1350 regainControl
  1329     keepMenu ifTrue:[
  1351     true ifTrue:[
  1330         device grabPointerInView:self.
  1352 	device grabPointerInView:self.
  1331         device grabKeyboardInView:self.
  1353 	device grabKeyboardInView:self.
  1332 "/        self cursor:Cursor upRightArrow
  1354 "/        self cursor:Cursor upRightArrow
  1333         self sensor flushMotionEventsFor:nil
  1355 	self sensor flushMotionEventsFor:nil
  1334     ]
  1356     ]
  1335 
  1357 
  1336     "Modified: 6.3.1996 / 17:14:27 / cg"
  1358     "Modified: 6.3.1996 / 17:14:27 / cg"
  1337 ! !
  1359 ! !
  1338 
  1360 
  1342     "when my container changes, all of my menus must change as well"
  1364     "when my container changes, all of my menus must change as well"
  1343 
  1365 
  1344     super container:aView.
  1366     super container:aView.
  1345 
  1367 
  1346     menus notNil ifTrue:[
  1368     menus notNil ifTrue:[
  1347         menus do:[:aMenu |
  1369 	menus do:[:aMenu |
  1348             aMenu notNil ifTrue:[
  1370 	    aMenu notNil ifTrue:[
  1349                 aMenu container:aView
  1371 		aMenu container:aView
  1350             ]
  1372 	    ]
  1351         ]
  1373 	]
  1352     ]
  1374     ]
  1353 
  1375 
  1354     "Modified: 9.5.1996 / 00:43:13 / cg"
  1376     "Modified: 9.5.1996 / 00:43:13 / cg"
  1355     "Created: 9.5.1996 / 00:43:38 / cg"
  1377     "Created: 9.5.1996 / 00:43:38 / cg"
  1356 !
  1378 !
  1405 
  1427 
  1406 "/    DefaultFont notNil ifTrue:[font := DefaultFont on:device].
  1428 "/    DefaultFont notNil ifTrue:[font := DefaultFont on:device].
  1407 
  1429 
  1408     showSeparatingLines := DefaultSeparatingLines. "/ false.
  1430     showSeparatingLines := DefaultSeparatingLines. "/ false.
  1409     DefaultViewBackground notNil ifTrue:[
  1431     DefaultViewBackground notNil ifTrue:[
  1410         viewBackground := DefaultViewBackground on:device
  1432 	viewBackground := DefaultViewBackground on:device
  1411     ].
  1433     ].
  1412 
  1434 
  1413     DefaultForegroundColor notNil ifTrue:[
  1435     DefaultForegroundColor notNil ifTrue:[
  1414         fgColor := DefaultForegroundColor
  1436 	fgColor := DefaultForegroundColor
  1415     ] ifFalse:[
  1437     ] ifFalse:[
  1416         fgColor := Black.
  1438 	fgColor := Black.
  1417     ].
  1439     ].
  1418     DefaultBackgroundColor notNil ifTrue:[
  1440     DefaultBackgroundColor notNil ifTrue:[
  1419         bgColor := DefaultBackgroundColor
  1441 	bgColor := DefaultBackgroundColor
  1420     ] ifFalse:[
  1442     ] ifFalse:[
  1421         bgColor := viewBackground.
  1443 	bgColor := viewBackground.
  1422     ].
  1444     ].
  1423     onLevel := DefaultHilightLevel.
  1445     onLevel := DefaultHilightLevel.
  1424     offLevel := DefaultLevel.
  1446     offLevel := DefaultLevel.
  1425 
  1447 
  1426     self is3D ifTrue:[
  1448     self is3D ifTrue:[
  1427         device hasColors ifTrue:[
  1449 	device hasColors ifTrue:[
  1428             activeFgColor := Color name:'yellow'
  1450 	    activeFgColor := Color name:'yellow'
  1429         ] ifFalse:[
  1451 	] ifFalse:[
  1430             activeFgColor := White
  1452 	    activeFgColor := White
  1431         ].
  1453 	].
  1432         device hasGrayscales ifTrue:[
  1454 	device hasGrayscales ifTrue:[
  1433             activeBgColor := bgColor.
  1455 	    activeBgColor := bgColor.
  1434         ] ifFalse:[
  1456 	] ifFalse:[
  1435             activeBgColor := fgColor.
  1457 	    activeBgColor := fgColor.
  1436         ].
  1458 	].
  1437         topMargin := 2.
  1459 	topMargin := 2.
  1438 
  1460 
  1439         style := styleSheet name.
  1461 	style := styleSheet name.
  1440         ((style == #iris) or:[style == #motif]) ifTrue:[
  1462 	((style == #iris) or:[style == #motif]) ifTrue:[
  1441             self level:2.
  1463 	    self level:2.
  1442             onLevel := 2.
  1464 	    onLevel := 2.
  1443             offLevel := 0.
  1465 	    offLevel := 0.
  1444             activeFgColor := fgColor
  1466 	    activeFgColor := fgColor
  1445         ]
  1467 	]
  1446     ] ifFalse:[
  1468     ] ifFalse:[
  1447         activeFgColor := bgColor.
  1469 	activeFgColor := bgColor.
  1448         activeBgColor := fgColor.
  1470 	activeBgColor := fgColor.
  1449         topMargin := 0
  1471 	topMargin := 0
  1450     ].
  1472     ].
  1451 
  1473 
  1452     edgeStyle := DefaultEdgeStyle.
  1474     edgeStyle := DefaultEdgeStyle.
  1453     keepMenu := DefaultKeepMenu.
  1475     toggleMode := DefaultToggleMode.
  1454     toggleKeep := DefaultToggleKeep.
       
  1455 
  1476 
  1456     DefaultHilightForegroundColor notNil ifTrue:[
  1477     DefaultHilightForegroundColor notNil ifTrue:[
  1457         activeFgColor := DefaultHilightForegroundColor
  1478 	activeFgColor := DefaultHilightForegroundColor
  1458     ].
  1479     ].
  1459     DefaultHilightBackgroundColor notNil ifTrue:[
  1480     DefaultHilightBackgroundColor notNil ifTrue:[
  1460         activeBgColor := DefaultHilightBackgroundColor
  1481 	activeBgColor := DefaultHilightBackgroundColor
  1461     ].
  1482     ].
  1462     DefaultShadowColor notNil ifTrue:[
  1483     DefaultShadowColor notNil ifTrue:[
  1463         shadowColor := DefaultShadowColor
  1484 	shadowColor := DefaultShadowColor
  1464     ].
  1485     ].
  1465     DefaultLightColor notNil ifTrue:[
  1486     DefaultLightColor notNil ifTrue:[
  1466         lightColor := DefaultLightColor
  1487 	lightColor := DefaultLightColor
  1467     ].
  1488     ].
  1468 
  1489 
  1469     raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true.
  1490     raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true.
  1470 
  1491 
  1471     "Modified: 17.1.1997 / 23:22:13 / cg"
  1492     "Modified: 17.1.1997 / 23:22:13 / cg"
  1484     "if the image was saved with an active menu, hide it"
  1505     "if the image was saved with an active menu, hide it"
  1485 
  1506 
  1486     |m|
  1507     |m|
  1487 
  1508 
  1488     activeMenuNumber notNil ifTrue:[
  1509     activeMenuNumber notNil ifTrue:[
  1489         (m := menus at:activeMenuNumber) notNil ifTrue:[
  1510 	(m := menus at:activeMenuNumber) notNil ifTrue:[
  1490             m unmap.
  1511 	    m unmap.
  1491         ].
  1512 	].
  1492         activeMenuNumber := nil.
  1513 	activeMenuNumber := nil.
  1493     ].
  1514     ].
  1494     super recreate.
  1515     super recreate.
  1495     self setMenuOrigins
  1516     self setMenuOrigins
  1496 
  1517 
  1497     "Modified: 3.5.1996 / 23:48:55 / stefan"
  1518     "Modified: 3.5.1996 / 23:48:55 / stefan"
  1506      If stringOrNumber is not a valid item, return 0."
  1527      If stringOrNumber is not a valid item, return 0."
  1507 
  1528 
  1508     |idx|
  1529     |idx|
  1509 
  1530 
  1510     stringOrNumber isNumber ifTrue:[
  1531     stringOrNumber isNumber ifTrue:[
  1511         ^ stringOrNumber
  1532 	^ stringOrNumber
  1512     ].
  1533     ].
  1513     selectors notNil ifTrue:[
  1534     selectors notNil ifTrue:[
  1514         idx := selectors indexOf:stringOrNumber.
  1535 	idx := selectors indexOf:stringOrNumber.
  1515         idx ~~ 0 ifTrue:[^ idx].
  1536 	idx ~~ 0 ifTrue:[^ idx].
  1516     ].
  1537     ].
  1517     stringOrNumber isString ifTrue:[
  1538     stringOrNumber isString ifTrue:[
  1518         ^ titles indexOf:stringOrNumber
  1539 	^ titles indexOf:stringOrNumber
  1519     ].
  1540     ].
  1520     (stringOrNumber respondsTo:#string) ifTrue:[
  1541     (stringOrNumber respondsTo:#string) ifTrue:[
  1521         ^ titles indexOf:stringOrNumber asString
  1542 	^ titles indexOf:stringOrNumber asString
  1522     ].
  1543     ].
  1523     ^ 0
  1544     ^ 0
  1524 
  1545 
  1525     "Modified: 27.4.1996 / 15:25:28 / cg"
  1546     "Modified: 27.4.1996 / 15:25:28 / cg"
  1526 !
  1547 !
  1527 
  1548 
  1528 performEntry:itemIndex
  1549 performEntry:itemIndex
  1529     |block sel|
  1550     |block sel|
  1530 
  1551 
  1531     actions notNil ifTrue:[
  1552     actions notNil ifTrue:[
  1532         block := actions at:itemIndex.
  1553 	block := actions at:itemIndex.
  1533         block notNil ifTrue:[
  1554 	block notNil ifTrue:[
  1534             block value.
  1555 	    block value.
  1535             ^ self
  1556 	    ^ self
  1536         ].
  1557 	].
  1537     ].
  1558     ].
  1538     selectors notNil ifTrue:[
  1559     selectors notNil ifTrue:[
  1539         sel := selectors at:itemIndex.
  1560 	sel := selectors at:itemIndex.
  1540         sel notNil ifTrue:[
  1561 	sel notNil ifTrue:[
  1541             model notNil ifTrue:[
  1562 	    model notNil ifTrue:[
  1542                 model perform:sel
  1563 		model perform:sel
  1543             ] ifFalse:[
  1564 	    ] ifFalse:[
  1544                 receiver perform:sel
  1565 		receiver perform:sel
  1545             ]    
  1566 	    ]    
  1546         ].
  1567 	].
  1547     ].
  1568     ].
  1548 
  1569 
  1549     "Modified: 17.4.1996 / 20:55:11 / cg"
  1570     "Modified: 17.4.1996 / 20:55:11 / cg"
  1550 !
  1571 !
  1551 
  1572 
  1552 performSelectedAction
  1573 performSelectedAction
  1553     |block sel|
  1574     |block sel|
  1554 
  1575 
  1555     actions notNil ifTrue:[
  1576     actions notNil ifTrue:[
  1556         block := actions at:activeMenuNumber.
  1577 	block := actions at:activeMenuNumber.
  1557         block notNil ifTrue:[
  1578 	block notNil ifTrue:[
  1558             block value.
  1579 	    block value.
  1559             ^ self
  1580 	    ^ self
  1560         ].
  1581 	].
  1561     ].
  1582     ].
  1562     selectors notNil ifTrue:[
  1583     selectors notNil ifTrue:[
  1563         sel := selectors at:activeMenuNumber.
  1584 	sel := selectors at:activeMenuNumber.
  1564         sel notNil ifTrue:[
  1585 	sel notNil ifTrue:[
  1565             model notNil ifTrue:[
  1586 	    model notNil ifTrue:[
  1566                 model perform:sel
  1587 		model perform:sel
  1567             ] ifFalse:[
  1588 	    ] ifFalse:[
  1568                 receiver perform:sel
  1589 		receiver perform:sel
  1569             ]    
  1590 	    ]    
  1570         ].
  1591 	].
  1571     ].
  1592     ].
  1572 
  1593 
  1573     "Modified: 17.4.1996 / 20:55:11 / cg"
  1594     "Modified: 17.4.1996 / 20:55:11 / cg"
  1574     "Created: 17.4.1996 / 20:55:53 / cg"
  1595     "Created: 17.4.1996 / 20:55:53 / cg"
  1575 !
  1596 !
  1576 
  1597 
  1577 setMenuOrigins
  1598 setMenuOrigins
  1578     "adjust origins of menus when font changes"
  1599     "adjust origins of menus when font changes"
  1579 
  1600 
  1580     (font graphicsDevice == device) ifTrue:[
  1601     (font graphicsDevice == device) ifTrue:[
  1581         menus notNil ifTrue:[
  1602 	menus notNil ifTrue:[
  1582             menus keysAndValuesDo:[:index :aMenu |
  1603 	    menus keysAndValuesDo:[:index :aMenu |
  1583                 aMenu notNil ifTrue:[
  1604 		aMenu notNil ifTrue:[
  1584                     aMenu origin:((left + (self titleLenUpTo:index)) 
  1605 		    aMenu origin:((left + (self titleLenUpTo:index)) 
  1585                                   @
  1606 				  @
  1586                                   (height + aMenu borderWidth))
  1607 				  (height + aMenu borderWidth))
  1587                 ].
  1608 		].
  1588             ]
  1609 	    ]
  1589         ]
  1610 	]
  1590     ]
  1611     ]
  1591 
  1612 
  1592     "Modified: 5.7.1996 / 17:55:08 / cg"
  1613     "Modified: 5.7.1996 / 17:55:08 / cg"
  1593 !
  1614 !
  1594 
  1615 
  1692     |w hMax|
  1713     |w hMax|
  1693 
  1714 
  1694     "/ If I have an explicit preferredExtent ..
  1715     "/ If I have an explicit preferredExtent ..
  1695 
  1716 
  1696     preferredExtent notNil ifTrue:[
  1717     preferredExtent notNil ifTrue:[
  1697         ^ preferredExtent
  1718 	^ preferredExtent
  1698     ].
  1719     ].
  1699 
  1720 
  1700     w := self titleLenUpTo:(titles size + 1).
  1721     w := self titleLenUpTo:(titles size + 1).
  1701     hMax := font height + (font descent * 2).
  1722     hMax := font height + (font descent * 2).
  1702     titles notNil ifTrue:[
  1723     titles notNil ifTrue:[
  1703         titles do:[:aStringOrImage |
  1724 	titles do:[:aStringOrImage |
  1704             aStringOrImage isString ifFalse:[
  1725 	    aStringOrImage isString ifFalse:[
  1705                 hMax := hMax max:(aStringOrImage heightOn:self)
  1726 		hMax := hMax max:(aStringOrImage heightOn:self)
  1706             ]
  1727 	    ]
  1707         ]
  1728 	]
  1708     ].
  1729     ].
  1709         
  1730         
  1710     ^ w @ (hMax + (margin*2) + ((onLevel abs max:offLevel abs)*2) "+ topMargin").
  1731     ^ w @ (hMax + (margin*2) + ((onLevel abs max:offLevel abs)*2) "+ topMargin").
  1711 
  1732 
  1712     "Modified: / 31.10.1997 / 20:49:23 / cg"
  1733     "Modified: / 31.10.1997 / 20:49:23 / cg"
  1752 ! !
  1773 ! !
  1753 
  1774 
  1754 !PullDownMenu class methodsFor:'documentation'!
  1775 !PullDownMenu class methodsFor:'documentation'!
  1755 
  1776 
  1756 version
  1777 version
  1757     ^ '$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.80 1997-11-02 17:52:14 cg Exp $'
  1778     ^ '$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.81 1997-11-20 18:02:20 cg Exp $'
  1758 ! !
  1779 ! !