'From VisualWorks(R), Release 2.5 of September 26, 1995 on October 28, 1996 at 10:07:53 am'! MenuItemView subclass: #SmalltalkMenuItemView instanceVariableNames: 'composedLabel ' classVariableNames: 'IndicationOffIcon IndicationOnIcon SubmenuIcon ' poolDictionaries: '' category: 'UILooks-Default'! !SmalltalkMenuItemView methodsFor: 'displaying'! displayOn: aGraphicsContext "Display the receiver on aGraphicsContext" | theDisplayBox | theDisplayBox := self bounds. self isSelection ifTrue: [ self displaySelectionBackgroundOn: aGraphicsContext in: theDisplayBox. aGraphicsContext paint: self selectionForegroundColor] ifFalse: [aGraphicsContext paint: self foregroundColor]. model hasIndication ifTrue: [self displayIndicationOn: aGraphicsContext in: theDisplayBox]. self displayLabelOn: aGraphicsContext in: theDisplayBox. model hasSubmenu ifTrue: [self displaySubmenuIndicatorOn: aGraphicsContext in: theDisplayBox].! ! !SmalltalkMenuItemView methodsFor: 'displaying-private'! composedLabel "Answer the composed text for the label of this menu item." composedLabel == nil ifTrue: [ | text | (text := self menuItem labelText) == nil ifTrue: [ text := self menuItem label asText]. composedLabel := Label with: text attributes: DefaultLookPolicy systemMenuTextStyle]. ^composedLabel! displayIndicationOn: aGraphicsContext in: theMenuItemBox "Display the indication state of the menu item on aGraphicsContext inside theMenuItemBox." (model isOn ifTrue: [IndicationOnIcon] ifFalse: [IndicationOffIcon]) displayOn: aGraphicsContext at: 2 @ ((theMenuItemBox height - (IndicationOnIcon height - 1)) // 2)! displayLabelOn: aGraphicsContext in: theMenuItemBox "Display the label of the menu item on aGraphicsContext inside theMenuItemBox. isSelected indicates if the menu item is to be displayed in it's selected 'highlighted' state." self composedLabel displayOn: aGraphicsContext at: self labelIndent @ ((theMenuItemBox height - self composedLabel height) // 2)! displaySelectionBackgroundOn: aGraphicsContext in: theDisplayBox "Display the background on aGraphicsContext (inside theDisplayBox) to indicate that the menu item is currently selected (highlighted)." aGraphicsContext paint: self selectionBackgroundColor; displayRectangle: theDisplayBox! displaySubmenuIndicatorOn: aGraphicsContext in: theDisplayBox "Display the submenu indicator on the right edge of the menu item." SubmenuIcon displayOn: aGraphicsContext at: (theDisplayBox right - self submenuIndent + 1) @ ((theDisplayBox height - (SubmenuIcon height - 1)) // 2)! ! !SmalltalkMenuItemView methodsFor: 'privileged'! labelIndent "Answer an indent for the label" ^menuView hasIndications ifTrue: [4 + IndicationOnIcon width] ifFalse: [2]! openSubMenu "One the submenu of this menu item." (SmalltalkMenuView model: model submenu) openFromParentMenuItemView: self! preferredExtent "Answer a preferred extent for the menu item view." ^self preferredWidth @ self preferredHeight! preferredHeight "Answer a preferred height for the menu item view." "Use the label's font baseline, not the gridline answered by Label>>height" ^self composedLabel attributes baseline! preferredWidth "Answer a preferred width for the menu item view." ^(self labelIndent * 2) + self composedLabel width + self submenuIndent! submenuIndent "Answer an indent for the submenu" ^model hasSubmenu ifTrue: [4 + SubmenuIcon width] ifFalse: [0]! ! !SmalltalkMenuItemView methodsFor: 'display box accessing'! preferredBounds "Answer a preferred bounding rectangle for the menu item view." ^Rectangle origin: 0 @ 0 extent: self preferredExtent! ! !SmalltalkMenuItemView class methodsFor: 'class initialization'! initialize "SmalltalkMenuItemView initialize" IndicationOnIcon := CachedImage on: ((Image extent: 5@5 depth: 1 palette: CoveragePalette monoMaskPalette bits: #[ 2r11111000 2r11110000 2r11111000 2r11110000 2r10101000] pad: 8)). IndicationOffIcon := CachedImage on: ((Image extent: 5@5 depth: 1 palette: CoveragePalette monoMaskPalette bits: #[ 2r11111000 2r10000000 2r10001000 2r10000000 2r10101000] pad: 8)). SubmenuIcon := CachedImage on: ((Image extent: 4@7 depth: 1 palette: CoveragePalette monoMaskPalette bits: #[ 2r10000000 2r01000000 2r10100000 2r00010000 2r10100000 2r01000000 2r10000000] pad: 8))! ! MenuView subclass: #SmalltalkMenuView instanceVariableNames: 'hasIndications ' classVariableNames: '' poolDictionaries: '' category: 'UILooks-Default'! !SmalltalkMenuView methodsFor: 'protected-menu item views'! computeMaxWidth "Compute the maximum width information of the menu items. Answer the maximum preferred widths of the bounding boxes of the menuItemViews. This is the appropriate width of the Composite containing the menuItemViews." ^self menuItemViews inject: 0 into: [:maxGroupWidth :eachGroup | maxGroupWidth max: (eachGroup inject: maxGroupWidth into: [:maxWidth :eachItem | maxWidth max: eachItem preferredWidth])]! menuItemViewForMenuItem: aMenuItem "Answer the appropriate MenuItemView for the receiver to be the view for aMenuItem." ^SmalltalkMenuItemView model: aMenuItem menuView: self! newHeightWithMenuItemViewGroup: menuItemViewGroup to: aComposite at: verticalPosition width: width "Add the given collection of MenuItemViews to the receiver (by putting them inside aComposite). Begin placing the views at the given verticalPosition in aComposite. The views occupy the given width (in pixels) of aComposite. Answer the new vertical position for placing the next group." "Add a separating line" verticalPosition = 0 ifFalse: [ aComposite addWrapper: (StrokingWrapper on: (LineSegment from: 0 @ verticalPosition to: width @ verticalPosition))]. ^super newHeightWithMenuItemViewGroup: menuItemViewGroup to: aComposite at: verticalPosition width: width! withBoundedWrapper "Answer the receiver wrapped in an appropriate bounded wrapper." ^(BorderedWrapper on: self) borderColor: self borderColor; borderWidthLeft: 1 right: 3 top: 1 bottom: 3; inset: 0! ! !SmalltalkMenuView methodsFor: 'visual properties'! backgroundColor ^ColorValue white! borderColor ^ColorValue black! foregroundColor ^ColorValue black! inactiveForegroundColor ^ColorValue lightGray! selectionBackgroundColor ^ColorValue black! selectionForegroundColor ^ColorValue white! separatorColor ^ColorValue black! ! !SmalltalkMenuView methodsFor: 'protected'! setColorsInMenuWindow: aWindow from: spawningViewOrNil "Set the color preferences for the menu window. If non-nil, spawningViewOrNil is the view that spawned the menu." aWindow background: self backgroundColor! topRightOffsetAsChildMenu "Answer the offset to position the receiver as a child menu from the topRight corner of the parent menu item views bounds." ^-2 @ -1! ! !SmalltalkMenuView methodsFor: 'privileged'! hasIndications "Answer true if any menu item has indications" hasIndications == nil ifTrue: [ hasIndications := (model menuItems contains: [:it | it hasIndication and: [it hidden not]]) or: [parentMenuItemView notNil and: [parentMenuItemView menuView hasIndications]]]. ^hasIndications! ! SmalltalkMenuItemView initialize! 'Only install this if we come here ...'! !SmalltalkWidgetPolicy methodsFor: 'menus'! menuViewForMenu: aMenuItemList "Answer an appropriate MenuView for displaying the given MenuItemList." ^SmalltalkMenuView model: aMenuItemList! !