MenuPanel.st
changeset 710 4453e463ff16
parent 709 4fbc1048fe05
child 711 08be3e0f494e
--- a/MenuPanel.st	Fri Jan 30 00:02:07 1998 +0100
+++ b/MenuPanel.st	Fri Jan 30 12:49:20 1998 +0100
@@ -30,7 +30,7 @@
 Object subclass:#Item
 	instanceVariableNames:'layout menuPanel subMenu adornment rawLabel enableChannel nameKey
 		accessCharacterPosition value label activeHelpKey submenuChannel
-		disabledImage isButton'
+		startGroup disabledImage isButton'
 	classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
 		VerticalButtonInset LabelRightOffset ShortcutKeyOffset
 		IndicatorOn IndicatorOff'
@@ -1473,10 +1473,44 @@
     "Modified: / 29.10.1997 / 15:48:33 / cg"
 !
 
+rearrangeGroups
+    |layout
+     dltX  "{ Class:SmallInteger }"
+     start "{ Class:SmallInteger }"
+    |
+
+    (self isPopUpView or:[self verticalLayout]) ifTrue:[
+        ^ self
+    ].
+
+    layout := items last layout.
+
+    (dltX := width - margin - 2 - layout right) <= 0 ifTrue:[
+        ^ self  "/ no free space
+    ].
+    start := items findFirst:[:anItem| anItem startGroup == #right ].
+
+    start == 0 ifTrue:[
+        ^ self  "/ no item detected
+    ].
+
+    "/ change layout
+
+    items from:start do:[:anItem|
+        layout := anItem layout.
+        layout  left:(layout  left + dltX).
+        layout right:(layout right + dltX).
+    ].
+!
+
 rearrangeItems
     "recompute layout of my items
     "
-    |expLast x y e grpDivSz layout isVert|
+    |expLast e grpDivSz layout isVert
+     x  "{ Class:SmallInteger }"
+     y  "{ Class:SmallInteger }"
+     noItems "{ Class:SmallInteger }"
+    |
 
     mustRearrange ifFalse:[ ^ self ].
 
@@ -1484,8 +1518,7 @@
     (superMenu notNil and:[superMenu font ~~ font]) ifTrue:[
         super font:(superMenu font on:device)
     ].
-
-    items isNil ifTrue:[
+    (noItems := items size) == 0 ifTrue:[
         mustRearrange := false.
       ^ self
     ].
@@ -1507,7 +1540,7 @@
                 items do:[:el|x := x + el preferredExtentX].
                 y := e x.
             ].
-            x := x + (items size + 1 * itemSpace).
+            x := x + (noItems + 1 * itemSpace).
 
             (grpDivSz := (y - x) // (groupSizes size)) <= 0 ifTrue:[
                 grpDivSz := nil
@@ -1549,12 +1582,14 @@
                   ifFalse:[x := x + grpDivSz]
         ]
     ].
+
     expLast ifTrue:[
         layout := items last layout.
 
         isVert ifTrue:[layout bottom:((self extent y) + 1)]
-              ifFalse:[layout right:((self extent x) + 1)].
+              ifFalse:[layout  right:((self extent x) + 1)].
     ].
+    self rearrangeGroups.
     mustRearrange := false.
 
 
@@ -1568,7 +1603,7 @@
     "
     |start end isVrt x1 x2 y1 y2 item layout lnSz hrzInset prevClipArea|
 
-    shown ifFalse:[^ self].
+    (shown and:[w ~~ 0]) ifFalse:[^ self].
 
     self  paint:(self backgroundColor).
     self  clearRectangleX:x y:y width:w height:h.
@@ -2433,7 +2468,7 @@
 canDrawItem
     "returns true if an item could be drawn otherwise false
     "
-    ^ (mustRearrange not and:[self shown])
+    ^ (mustRearrange not and:[shown])
 
 
 !
@@ -2829,6 +2864,25 @@
     ].
 !
 
+startGroup
+    "start group #left #right #center ... or nil
+     at the moment only #right is implemented
+    "
+    ^ startGroup
+!
+
+startGroup:aSymbol
+    "start group #left #right #center ...
+     at the moment only #right is implemented
+    "
+    (startGroup isNil or:[startGroup == #right]) ifTrue:[
+        startGroup := aSymbol
+    ] ifFalse:[
+        self warn:('not supported group: ', aSymbol printString ).
+    ]
+
+!
+
 submenu
     "returns my submenu or nil
     "
@@ -3215,6 +3269,7 @@
     ].
 
     item accessCharacterPosition:(self accessCharacterPosition).
+    item startGroup:(self startGroup).
     item argument:(self argument).
     item nameKey:(self nameKey).
     item shortcutKeyCharacter:(self shortcutKey).
@@ -3244,6 +3299,7 @@
         self nameKey:(aMenuItem nameKey).
         self indication:(aMenuItem indication).
         self isButton:(aMenuItem isButton).
+        self startGroup:(aMenuItem startGroup).
 
         (lbl := aMenuItem labelImage value) isNil ifTrue:[
             lbl := aMenuItem label.
@@ -4115,6 +4171,6 @@
 !MenuPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.56 1998-01-29 23:02:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.57 1998-01-30 11:49:20 ca Exp $'
 ! !
 MenuPanel initialize!