MenuPanel.st
changeset 710 4453e463ff16
parent 709 4fbc1048fe05
child 711 08be3e0f494e
equal deleted inserted replaced
709:4fbc1048fe05 710:4453e463ff16
    28 !
    28 !
    29 
    29 
    30 Object subclass:#Item
    30 Object subclass:#Item
    31 	instanceVariableNames:'layout menuPanel subMenu adornment rawLabel enableChannel nameKey
    31 	instanceVariableNames:'layout menuPanel subMenu adornment rawLabel enableChannel nameKey
    32 		accessCharacterPosition value label activeHelpKey submenuChannel
    32 		accessCharacterPosition value label activeHelpKey submenuChannel
    33 		disabledImage isButton'
    33 		startGroup disabledImage isButton'
    34 	classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
    34 	classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
    35 		VerticalButtonInset LabelRightOffset ShortcutKeyOffset
    35 		VerticalButtonInset LabelRightOffset ShortcutKeyOffset
    36 		IndicatorOn IndicatorOff'
    36 		IndicatorOn IndicatorOff'
    37 	poolDictionaries:''
    37 	poolDictionaries:''
    38 	privateIn:MenuPanel
    38 	privateIn:MenuPanel
  1471     ]
  1471     ]
  1472 
  1472 
  1473     "Modified: / 29.10.1997 / 15:48:33 / cg"
  1473     "Modified: / 29.10.1997 / 15:48:33 / cg"
  1474 !
  1474 !
  1475 
  1475 
       
  1476 rearrangeGroups
       
  1477     |layout
       
  1478      dltX  "{ Class:SmallInteger }"
       
  1479      start "{ Class:SmallInteger }"
       
  1480     |
       
  1481 
       
  1482     (self isPopUpView or:[self verticalLayout]) ifTrue:[
       
  1483         ^ self
       
  1484     ].
       
  1485 
       
  1486     layout := items last layout.
       
  1487 
       
  1488     (dltX := width - margin - 2 - layout right) <= 0 ifTrue:[
       
  1489         ^ self  "/ no free space
       
  1490     ].
       
  1491     start := items findFirst:[:anItem| anItem startGroup == #right ].
       
  1492 
       
  1493     start == 0 ifTrue:[
       
  1494         ^ self  "/ no item detected
       
  1495     ].
       
  1496 
       
  1497     "/ change layout
       
  1498 
       
  1499     items from:start do:[:anItem|
       
  1500         layout := anItem layout.
       
  1501         layout  left:(layout  left + dltX).
       
  1502         layout right:(layout right + dltX).
       
  1503     ].
       
  1504 !
       
  1505 
  1476 rearrangeItems
  1506 rearrangeItems
  1477     "recompute layout of my items
  1507     "recompute layout of my items
  1478     "
  1508     "
  1479     |expLast x y e grpDivSz layout isVert|
  1509     |expLast e grpDivSz layout isVert
       
  1510      x  "{ Class:SmallInteger }"
       
  1511      y  "{ Class:SmallInteger }"
       
  1512      noItems "{ Class:SmallInteger }"
       
  1513     |
  1480 
  1514 
  1481     mustRearrange ifFalse:[ ^ self ].
  1515     mustRearrange ifFalse:[ ^ self ].
  1482 
  1516 
  1483 "/  fetch font from superMenu
  1517 "/  fetch font from superMenu
  1484     (superMenu notNil and:[superMenu font ~~ font]) ifTrue:[
  1518     (superMenu notNil and:[superMenu font ~~ font]) ifTrue:[
  1485         super font:(superMenu font on:device)
  1519         super font:(superMenu font on:device)
  1486     ].
  1520     ].
  1487 
  1521     (noItems := items size) == 0 ifTrue:[
  1488     items isNil ifTrue:[
       
  1489         mustRearrange := false.
  1522         mustRearrange := false.
  1490       ^ self
  1523       ^ self
  1491     ].
  1524     ].
  1492     expLast  := false.
  1525     expLast  := false.
  1493     isVert   := self verticalLayout.
  1526     isVert   := self verticalLayout.
  1505                 y := e y.
  1538                 y := e y.
  1506             ] ifFalse:[
  1539             ] ifFalse:[
  1507                 items do:[:el|x := x + el preferredExtentX].
  1540                 items do:[:el|x := x + el preferredExtentX].
  1508                 y := e x.
  1541                 y := e x.
  1509             ].
  1542             ].
  1510             x := x + (items size + 1 * itemSpace).
  1543             x := x + (noItems + 1 * itemSpace).
  1511 
  1544 
  1512             (grpDivSz := (y - x) // (groupSizes size)) <= 0 ifTrue:[
  1545             (grpDivSz := (y - x) // (groupSizes size)) <= 0 ifTrue:[
  1513                 grpDivSz := nil
  1546                 grpDivSz := nil
  1514             ]
  1547             ]
  1515         ]
  1548         ]
  1547         (grpDivSz notNil and:[self hasGroupDividerAt:anIndex]) ifTrue:[
  1580         (grpDivSz notNil and:[self hasGroupDividerAt:anIndex]) ifTrue:[
  1548             isVert ifTrue:[y := y + grpDivSz]
  1581             isVert ifTrue:[y := y + grpDivSz]
  1549                   ifFalse:[x := x + grpDivSz]
  1582                   ifFalse:[x := x + grpDivSz]
  1550         ]
  1583         ]
  1551     ].
  1584     ].
       
  1585 
  1552     expLast ifTrue:[
  1586     expLast ifTrue:[
  1553         layout := items last layout.
  1587         layout := items last layout.
  1554 
  1588 
  1555         isVert ifTrue:[layout bottom:((self extent y) + 1)]
  1589         isVert ifTrue:[layout bottom:((self extent y) + 1)]
  1556               ifFalse:[layout right:((self extent x) + 1)].
  1590               ifFalse:[layout  right:((self extent x) + 1)].
  1557     ].
  1591     ].
       
  1592     self rearrangeGroups.
  1558     mustRearrange := false.
  1593     mustRearrange := false.
  1559 
  1594 
  1560 
  1595 
  1561 
  1596 
  1562 
  1597 
  1566 redrawX:x y:y width:w height:h
  1601 redrawX:x y:y width:w height:h
  1567     "redraw a rectangle
  1602     "redraw a rectangle
  1568     "
  1603     "
  1569     |start end isVrt x1 x2 y1 y2 item layout lnSz hrzInset prevClipArea|
  1604     |start end isVrt x1 x2 y1 y2 item layout lnSz hrzInset prevClipArea|
  1570 
  1605 
  1571     shown ifFalse:[^ self].
  1606     (shown and:[w ~~ 0]) ifFalse:[^ self].
  1572 
  1607 
  1573     self  paint:(self backgroundColor).
  1608     self  paint:(self backgroundColor).
  1574     self  clearRectangleX:x y:y width:w height:h.
  1609     self  clearRectangleX:x y:y width:w height:h.
  1575 
  1610 
  1576     isVrt := self verticalLayout.
  1611     isVrt := self verticalLayout.
  2431 !MenuPanel methodsFor:'queries'!
  2466 !MenuPanel methodsFor:'queries'!
  2432 
  2467 
  2433 canDrawItem
  2468 canDrawItem
  2434     "returns true if an item could be drawn otherwise false
  2469     "returns true if an item could be drawn otherwise false
  2435     "
  2470     "
  2436     ^ (mustRearrange not and:[self shown])
  2471     ^ (mustRearrange not and:[shown])
  2437 
  2472 
  2438 
  2473 
  2439 !
  2474 !
  2440 
  2475 
  2441 containsPoint:aPoint
  2476 containsPoint:aPoint
  2825     "
  2860     "
  2826     self shortcutKey ~~ aKey ifTrue:[
  2861     self shortcutKey ~~ aKey ifTrue:[
  2827         self adornment shortcutKey:aKey.
  2862         self adornment shortcutKey:aKey.
  2828         self redraw.
  2863         self redraw.
  2829     ].
  2864     ].
       
  2865 !
       
  2866 
       
  2867 startGroup
       
  2868     "start group #left #right #center ... or nil
       
  2869      at the moment only #right is implemented
       
  2870     "
       
  2871     ^ startGroup
       
  2872 !
       
  2873 
       
  2874 startGroup:aSymbol
       
  2875     "start group #left #right #center ...
       
  2876      at the moment only #right is implemented
       
  2877     "
       
  2878     (startGroup isNil or:[startGroup == #right]) ifTrue:[
       
  2879         startGroup := aSymbol
       
  2880     ] ifFalse:[
       
  2881         self warn:('not supported group: ', aSymbol printString ).
       
  2882     ]
       
  2883 
  2830 !
  2884 !
  2831 
  2885 
  2832 submenu
  2886 submenu
  2833     "returns my submenu or nil
  2887     "returns my submenu or nil
  2834     "
  2888     "
  3213     enableChannel notNil ifTrue:[
  3267     enableChannel notNil ifTrue:[
  3214         item enabled:(enableChannel value)
  3268         item enabled:(enableChannel value)
  3215     ].
  3269     ].
  3216 
  3270 
  3217     item accessCharacterPosition:(self accessCharacterPosition).
  3271     item accessCharacterPosition:(self accessCharacterPosition).
       
  3272     item startGroup:(self startGroup).
  3218     item argument:(self argument).
  3273     item argument:(self argument).
  3219     item nameKey:(self nameKey).
  3274     item nameKey:(self nameKey).
  3220     item shortcutKeyCharacter:(self shortcutKey).
  3275     item shortcutKeyCharacter:(self shortcutKey).
  3221     item value:(value value).
  3276     item value:(value value).
  3222     item indication:(self indication value).
  3277     item indication:(self indication value).
  3242         activeHelpKey := aMenuItem activeHelpKey.
  3297         activeHelpKey := aMenuItem activeHelpKey.
  3243         self enabled:(aMenuItem enabled).
  3298         self enabled:(aMenuItem enabled).
  3244         self nameKey:(aMenuItem nameKey).
  3299         self nameKey:(aMenuItem nameKey).
  3245         self indication:(aMenuItem indication).
  3300         self indication:(aMenuItem indication).
  3246         self isButton:(aMenuItem isButton).
  3301         self isButton:(aMenuItem isButton).
       
  3302         self startGroup:(aMenuItem startGroup).
  3247 
  3303 
  3248         (lbl := aMenuItem labelImage value) isNil ifTrue:[
  3304         (lbl := aMenuItem labelImage value) isNil ifTrue:[
  3249             lbl := aMenuItem label.
  3305             lbl := aMenuItem label.
  3250         ].
  3306         ].
  3251         self label:lbl.
  3307         self label:lbl.
  4113 ! !
  4169 ! !
  4114 
  4170 
  4115 !MenuPanel class methodsFor:'documentation'!
  4171 !MenuPanel class methodsFor:'documentation'!
  4116 
  4172 
  4117 version
  4173 version
  4118     ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.56 1998-01-29 23:02:07 cg Exp $'
  4174     ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.57 1998-01-30 11:49:20 ca Exp $'
  4119 ! !
  4175 ! !
  4120 MenuPanel initialize!
  4176 MenuPanel initialize!