MenuPanel.st
changeset 2364 c72f35819bda
parent 2362 7a0f2e986289
child 2372 d136f6d4b7c5
equal deleted inserted replaced
2363:72cda227e48d 2364:c72f35819bda
    28 !
    28 !
    29 
    29 
    30 Object subclass:#Item
    30 Object subclass:#Item
    31 	instanceVariableNames:'menuItem layout menuPanel subMenu rawLabel rawLabelExtent
    31 	instanceVariableNames:'menuItem layout menuPanel subMenu rawLabel rawLabelExtent
    32 		disabledRawLabel enableChannel label activeHelpText flyByHelpText
    32 		disabledRawLabel enableChannel label activeHelpText flyByHelpText
    33 		submenuChannel isVisible indication choice accessCharacter font'
    33 		isVisible indication choice accessCharacter font'
    34 	classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
    34 	classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
    35 		VerticalButtonInset LabelRightOffset VerticalPopUpInset'
    35 		VerticalButtonInset LabelRightOffset VerticalPopUpInset'
    36 	poolDictionaries:''
    36 	poolDictionaries:''
    37 	privateIn:MenuPanel
    37 	privateIn:MenuPanel
    38 !
    38 !
  5026         ] ifFalse:[
  5026         ] ifFalse:[
  5027             "/ use font from menupanel
  5027             "/ use font from menupanel
  5028             font := nil
  5028             font := nil
  5029         ].
  5029         ].
  5030 
  5030 
  5031         rawLabel isEmptyOrNil ifFalse:[
  5031         rawLabel isString ifTrue:[
  5032             "have to recompute the extent"
  5032             "have to recompute the extent"
  5033             self label:label
  5033             self label:label
  5034         ]
  5034         ]
  5035     ].
  5035     ].
  5036 !
  5036 !
  5221         subMenu menu:aSubMenu.
  5221         subMenu menu:aSubMenu.
  5222     ] ifFalse:[
  5222     ] ifFalse:[
  5223         aSubMenu isView ifFalse:[
  5223         aSubMenu isView ifFalse:[
  5224             (aSubMenu isKindOf:ApplicationModel) ifFalse:[
  5224             (aSubMenu isKindOf:ApplicationModel) ifFalse:[
  5225                 "/ ... mhhhh ....
  5225                 "/ ... mhhhh ....
  5226                 ^ self submenuChannel:aSubMenu
  5226                 ^ menuItem submenuChannel:aSubMenu
  5227             ].            
  5227             ].            
  5228             widget := SimpleView new.
  5228             widget := SimpleView new.
  5229             widget client:aSubMenu.
  5229             widget client:aSubMenu.
  5230         ] ifTrue:[
  5230         ] ifTrue:[
  5231             widget := aSubMenu
  5231             widget := aSubMenu
  5244             subMenu extent:(widget preferredExtent).
  5244             subMenu extent:(widget preferredExtent).
  5245             widget origin:0.0@0.0 corner:1.0@1.0.
  5245             widget origin:0.0@0.0 corner:1.0@1.0.
  5246         ].
  5246         ].
  5247         subMenu superMenu:menuPanel.
  5247         subMenu superMenu:menuPanel.
  5248     ].
  5248     ].
  5249     menuItem keepLinkedMenu ifTrue:[
       
  5250         submenuChannel := nil
       
  5251     ]
       
  5252 !
  5249 !
  5253 
  5250 
  5254 textLabel
  5251 textLabel
  5255     "returns my textLabel or nil if none text
  5252     "returns my textLabel or nil if none text
  5256     "
  5253     "
  5355 enabled
  5352 enabled
  5356     "returns the enabled state
  5353     "returns the enabled state
  5357     "
  5354     "
  5358     |state|
  5355     |state|
  5359 
  5356 
  5360     menuPanel enabled ifTrue:[
  5357     menuPanel enabled ifFalse:[^ false].
  5361 	enableChannel isSymbol ifTrue:[
  5358 
  5362 	    state := self aspectAt:enableChannel.
  5359     enableChannel isSymbol ifTrue:[
  5363 	    state isNil ifTrue:[
  5360         state := self aspectAt:enableChannel.
  5364 		self ifNotInUIBuilderInfoPrintCR:
  5361 
  5365 		    ('MenuPanel::Item [info]: no aspect for ', enableChannel, ' (in ' , (label?rawLabel) printString , ')')
  5362         state isNil ifTrue:[
  5366 	    ] ifFalse:[
  5363             self ifNotInUIBuilderInfoPrintCR:
  5367 		state isValueModel ifTrue:[
  5364                 ('MenuPanel::Item [info]: no aspect for ', enableChannel, ' (in ' , label printString , ')').
  5368 		    enableChannel := state.
  5365             ^ true
  5369 		    enableChannel addDependent:self.
  5366         ].
  5370 		    state := enableChannel value.
  5367 
  5371 		] ifFalse:[
  5368         state isValueModel ifTrue:[
  5372 		    state := state value
  5369             enableChannel := state.
  5373 		]
  5370             enableChannel addDependent:self.
  5374 	    ]
  5371             state := enableChannel value.
  5375 	] ifFalse:[
  5372         ] ifFalse:[
  5376 	    state := enableChannel value
  5373             state := state value
  5377 	].
  5374         ]
  5378       ^ state ~~ false
  5375     ] ifFalse:[
  5379     ].
  5376         state := enableChannel value
  5380     ^ false
  5377     ].
       
  5378     ^ state ~~ false
  5381 !
  5379 !
  5382 
  5380 
  5383 enabled:something
  5381 enabled:something
  5384     "change the enabled state; if the state changed, a redraw is performed
  5382     "change the enabled state; if the state changed, a redraw is performed
  5385     "
  5383     "
  5489 !
  5487 !
  5490 
  5488 
  5491 submenuChannel
  5489 submenuChannel
  5492     "get the submenu channel
  5490     "get the submenu channel
  5493     "
  5491     "
  5494   ^ submenuChannel
  5492     ^ menuItem submenuChannel
  5495 !
  5493 !
  5496 
  5494 
  5497 submenuChannel:aSelectorOrNil
  5495 submenuChannel:aSelectorOrNil
  5498     "returns the submenu channel
  5496     "returns the submenu channel
  5499     "
  5497     "
  5500     submenuChannel := aSelectorOrNil.
  5498     menuItem submenuChannel:aSelectorOrNil.
  5501 ! !
  5499 ! !
  5502 
  5500 
  5503 !MenuPanel::Item methodsFor:'accessing-dimension'!
  5501 !MenuPanel::Item methodsFor:'accessing-dimension'!
  5504 
  5502 
  5505 moveBy:aPoint
  5503 moveBy:aPoint
  5698     |id|
  5696     |id|
  5699 
  5697 
  5700     aSubmenu ifNil:[^ self].
  5698     aSubmenu ifNil:[^ self].
  5701 
  5699 
  5702     aSubmenu realized ifFalse:[
  5700     aSubmenu realized ifFalse:[
  5703 	id := aSubmenu id.
  5701         id := aSubmenu id.
  5704 	id ifNotNil:[ menuPanel device unmapWindow:id ]
  5702         id ifNotNil:[ menuPanel device unmapWindow:id ]
  5705     ] ifTrue:[
  5703     ] ifTrue:[
  5706 	aSubmenu hide
  5704         aSubmenu hide
  5707     ].
  5705     ].
  5708 
  5706 
  5709     aSubmenu  windowGroup:nil.
  5707     aSubmenu  windowGroup:nil.
  5710     menuPanel windowGroup removeView:aSubmenu.
  5708     menuPanel windowGroup removeView:aSubmenu.
  5711 
  5709 
  5712     "/ release menu if derived from channel
  5710     "/ release menu if derived from channel
  5713     submenuChannel notNil ifTrue:[
  5711     (subMenu == aSubmenu and:[menuItem submenuChannel notNil]) ifTrue:[
  5714 	subMenu == aSubmenu ifTrue:[
  5712         menuItem keepLinkedMenu ifFalse:[
  5715 	    subMenu := nil
  5713             subMenu := nil
  5716 	]
  5714         ]
  5717     ].
  5715     ].
  5718 !
  5716 !
  5719 
  5717 
  5720 openDelayedSubmenu
  5718 openDelayedSubmenu
  5721     "called to open now my delayed submenu
  5719     "called to open now my delayed submenu
  5996 "/ but ... ??
  5994 "/ but ... ??
  5997         (lbl := menuItem labelImage value) isNil ifTrue:[
  5995         (lbl := menuItem labelImage value) isNil ifTrue:[
  5998             lbl := menuItem rawLabel. "/ avoid translating &'s twice
  5996             lbl := menuItem rawLabel. "/ avoid translating &'s twice
  5999         ].
  5997         ].
  6000 
  5998 
       
  5999         self submenu:(menuItem submenu).
  6001         self label:lbl.
  6000         self label:lbl.
  6002         submenuChannel := menuItem submenuChannel.
       
  6003         self submenu:(menuItem submenu).
       
  6004     ]
  6001     ]
  6005 
  6002 
  6006     "Modified: / 22.8.1998 / 15:34:16 / cg"
  6003     "Modified: / 22.8.1998 / 15:34:16 / cg"
  6007 ! !
  6004 ! !
  6008 
  6005 
  6724 
  6721 
  6725     |subm sel numArgs|
  6722     |subm sel numArgs|
  6726 
  6723 
  6727     aRecv isNil ifTrue:[^ nil].
  6724     aRecv isNil ifTrue:[^ nil].
  6728 
  6725 
  6729     sel := submenuChannel asSymbol.
  6726     sel := menuItem submenuChannel.
       
  6727     sel isString ifFalse:[^ nil].
       
  6728     sel := sel asSymbol.
  6730     numArgs := sel numArgs.
  6729     numArgs := sel numArgs.
  6731 
  6730 
  6732     numArgs == 0 ifTrue:[
  6731     numArgs == 0 ifTrue:[
  6733         MessageNotUnderstood handle:[:ex |
  6732         MessageNotUnderstood handle:[:ex |
  6734             |selector|
  6733             |selector|
  6896     ].
  6895     ].
  6897   ^ #blankLine
  6896   ^ #blankLine
  6898 !
  6897 !
  6899 
  6898 
  6900 setupSubmenu
  6899 setupSubmenu
  6901     |appl master recv submenuHolder submenu submenuEncoding|
  6900     |appl master recv submenuHolder submenu submenuEncoding channel|
  6902 
  6901 
  6903     submenuChannel notNil ifTrue:[
  6902     channel := menuItem submenuChannel value.
  6904         submenuChannel isSymbol ifFalse:[
  6903     channel isNil ifTrue:[ ^ subMenu ].
  6905             submenuHolder := submenuChannel
  6904 
  6906         ] ifTrue:[
  6905     subMenu notNil ifTrue:[
  6907             appl := menuPanel application.
  6906         menuItem keepLinkedMenu ifTrue:[ ^ subMenu ].
  6908             appl isNil ifTrue:[
  6907     ].
  6909                 appl := menuPanel receiver.
  6908 
  6910                 appl notNil ifTrue:[
  6909     channel isSymbol ifFalse:[
  6911                     (submenuHolder := self findSubMenuIn:appl) isNil ifTrue:[
  6910         submenuHolder := channel
  6912                         [submenuHolder isNil 
  6911     ] ifTrue:[
  6913                          and:[(master := appl perform:#masterApplication ifNotUnderstood:nil) notNil
  6912         appl := menuPanel application.
  6914                               and:[master ~~ appl]]] whileTrue:[
  6913         appl isNil ifTrue:[
  6915                             appl := master.
  6914             appl := menuPanel receiver.
  6916                             submenuHolder := self findSubMenuIn:appl.
  6915             appl notNil ifTrue:[
  6917                         ].
  6916                 (submenuHolder := self findSubMenuIn:appl) isNil ifTrue:[
  6918                     ]
  6917                     [submenuHolder isNil 
  6919                 ].
  6918                      and:[(master := appl perform:#masterApplication ifNotUnderstood:nil) notNil
       
  6919                           and:[master ~~ appl]]] whileTrue:[
       
  6920                         appl := master.
       
  6921                         submenuHolder := self findSubMenuIn:appl.
       
  6922                     ].
       
  6923                 ]
  6920             ].
  6924             ].
  6921             submenuHolder isNil ifTrue:[    
  6925         ].
  6922                 (submenuHolder := self findSubMenuIn:appl) isNil ifTrue:[
  6926         submenuHolder isNil ifTrue:[    
  6923                     (recv := menuPanel receiver) ~~ appl ifTrue:[
  6927             (submenuHolder := self findSubMenuIn:appl) isNil ifTrue:[
  6924                         appl := recv.
  6928                 (recv := menuPanel receiver) ~~ appl ifTrue:[
  6925                         submenuHolder := self findSubMenuIn:appl
  6929                     appl := recv.
  6926                     ]
  6930                     submenuHolder := self findSubMenuIn:appl
  6927                 ]
  6931                 ]
  6928             ]
  6932             ]
       
  6933         ]
       
  6934     ].
       
  6935 
       
  6936     (submenu := submenuHolder value) isArray ifTrue:[
       
  6937         submenuEncoding := submenu.    
       
  6938         submenu := Menu new fromLiteralArrayEncoding:submenuEncoding.
       
  6939         "/ cg: linked menus also may contain translations ...
       
  6940         submenu notNil ifTrue:[
       
  6941             appl notNil ifTrue:[
       
  6942                 submenu findGuiResourcesIn:appl.
       
  6943             ]                
  6929         ].
  6944         ].
  6930 
  6945     ].
  6931         (submenu := submenuHolder value) isArray ifTrue:[
  6946     "/ appl notNil ifTrue:[submenu application:appl].
  6932             submenuEncoding := submenu.    
  6947     self submenu:submenu.
  6933             submenu := Menu new fromLiteralArrayEncoding:submenuEncoding.
       
  6934             "/ cg: linked menus also may contain translations ...
       
  6935             submenu notNil ifTrue:[
       
  6936                 appl notNil ifTrue:[
       
  6937                     submenu findGuiResourcesIn:appl.
       
  6938                 ]                
       
  6939             ].
       
  6940         ].
       
  6941         "/ appl notNil ifTrue:[submenu application:appl].
       
  6942         self submenu:submenu.
       
  6943     ].
       
  6944 
       
  6945     ^ subMenu
  6948     ^ subMenu
  6946 
  6949 
  6947     "Modified: / 19.5.1998 / 19:36:56 / cg"
  6950     "Modified: / 19.5.1998 / 19:36:56 / cg"
  6948 ! !
  6951 ! !
  6949 
  6952 
  7032 !
  7035 !
  7033 
  7036 
  7034 hasSubmenu
  7037 hasSubmenu
  7035     "returns true if the item is configured as an subMenu entry
  7038     "returns true if the item is configured as an subMenu entry
  7036     "
  7039     "
  7037     ^ subMenu notNil or:[submenuChannel notNil]
  7040     ^ subMenu notNil or:[menuItem submenuChannel notNil]
  7038 !
  7041 !
  7039 
  7042 
  7040 isEnabled
  7043 isEnabled
  7041     "returns enabled state
  7044     "returns enabled state
  7042     "
  7045     "
  7375 ! !
  7378 ! !
  7376 
  7379 
  7377 !MenuPanel class methodsFor:'documentation'!
  7380 !MenuPanel class methodsFor:'documentation'!
  7378 
  7381 
  7379 version
  7382 version
  7380     ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.352 2002-11-08 15:32:20 ca Exp $'
  7383     ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.353 2002-11-11 10:29:41 ca Exp $'
  7381 ! !
  7384 ! !
  7382 
  7385 
  7383 MenuPanel initialize!
  7386 MenuPanel initialize!