MenuPanel.st
changeset 2614 86086fc6a99c
parent 2611 9814b5547d63
child 2617 1611c130d5e9
--- a/MenuPanel.st	Sat Jan 31 12:42:55 2004 +0100
+++ b/MenuPanel.st	Sun Feb 01 12:49:59 2004 +0100
@@ -1379,14 +1379,15 @@
 font:aFont
     "set the font
     "
-    (aFont notNil and:[aFont ~= font]) ifTrue:[
-	super font:(aFont "onDevice:device").
-
-	superMenu notNil ifTrue:[
-	    self extent:(self preferredExtent)
-	].
-	self mustRearrange.
-    ]
+    (aFont isNil or:[aFont = font]) ifTrue:[ ^ self ].
+
+    super font:aFont.
+    self do:[:anItem| anItem fontChanged ].
+
+    (shown and:[superMenu notNil]) ifTrue:[
+        self extent:(self preferredExtent)
+    ].
+    self mustRearrange.
 !
 
 foregroundColor
@@ -3623,7 +3624,7 @@
         rightArrowShadow := superMenu rightArrowShadow.
 
         self foregroundColor:(superMenu foregroundColor).
-        self            font:(superMenu font).
+        self             font:(superMenu font).
         self  viewBackground:(superMenu viewBackground).
     ].
 
@@ -4993,6 +4994,48 @@
     ^ displayLabel
 !
 
+displayLabelExtent
+    "returns the labelExtent
+    "
+    |prevFont w h|
+
+    displayLabelExtent notNil ifTrue:[
+        ^ displayLabelExtent
+    ].
+
+    displayLabel isNil ifTrue:[
+        displayLabelExtent := 0@0.
+        ^ displayLabelExtent
+    ].
+    prevFont := menuPanel setFont:(self font).
+
+    displayLabel isArray ifTrue:[
+        w := h := 0.
+
+        displayLabel do:[:aSubLabel|
+            aSubLabel notNil ifTrue:[
+                w := w max:(aSubLabel widthOn:menuPanel).
+                h := h + 1 + (aSubLabel heightOn:menuPanel).
+            ] ifFalse:[
+                h := h + (self spaceBetweenEmptyLines)
+            ]
+        ]
+    ] ifFalse:[
+        w := displayLabel  widthOn:menuPanel.
+        h := displayLabel heightOn:menuPanel.
+    ].
+    "/ care for italic fonts - give a few more pixels at the end
+    menuPanel font italic ifTrue:[
+        w := w + 2.
+    ].
+    displayLabelExtent := w@h.
+
+    prevFont notNil ifTrue:[
+        menuPanel setFont:prevFont.     "/ restore previous font
+    ].
+    ^ displayLabelExtent
+!
+
 font
     "returns the user configured font or nil (default menu font)
     "
@@ -5061,15 +5104,13 @@
     "set a new label; if the label changed, a redraw is performed;
      handle characters $& (ST-80 compatibility)
     "
-    |size char lbl mfont f oldExtent
-     h "{ Class:SmallInteger }"
-     w "{ Class:SmallInteger }"
-    |
-    oldExtent       := displayLabelExtent.
-    displayLabelExtent  := 0@0.
-    accessCharacter := disabledDisplayLabel := nil.
-    label           := aLabel value.
-    displayLabel    := label value ? ''.
+    |size char oldExtent|
+
+    oldExtent          := displayLabelExtent.
+    displayLabelExtent := nil. "/ force a recomputation
+    accessCharacter    := disabledDisplayLabel := nil.
+    label              := aLabel value.
+    displayLabel       := label value ? ''.
 
     displayLabel isString ifTrue:[
         "CHECK FOR SEPARATOR"
@@ -5078,7 +5119,7 @@
             size := displayLabel size.
 
             size == 0 ifTrue:[
-                displayLabel := nil.                        "blank separator"
+                displayLabel := nil.            "blank separator"
                 ^ self
             ].
 
@@ -5086,7 +5127,7 @@
                 char := displayLabel first.
 
                 (char == $- or:[char == $=]) ifTrue:[
-                    label    := displayLabel.               "line separator"
+                    label := displayLabel.      "line separator"
                     displayLabel := nil.
                     ^ self
                 ]
@@ -5097,41 +5138,26 @@
             displayLabel := displayLabel asArray.
         ]
     ].
-    mfont := menuPanel setFont:(self font).
-
-    displayLabel isArray ifTrue:[
-        w := h := 0.
-
-        displayLabel keysAndValuesDo:[:i :el|
-            el notNil ifTrue:[
-                lbl := self updateAccessCharacterFor:el.
-                displayLabel at:i put:lbl.
-                w := w max:(lbl widthOn:menuPanel).
-                h := h + 1 + (lbl heightOn:menuPanel).
-            ] ifFalse:[
-                h := h + (self spaceBetweenEmptyLines)
-            ]
+    displayLabel notNil ifTrue:[
+        displayLabel isArray ifTrue:[
+            displayLabel keysAndValuesDo:[:i :el|
+                el notNil ifTrue:[
+                    displayLabel at:i put:(self updateAccessCharacterFor:el).
+                ].
+            ].
+        ] ifFalse:[
+            displayLabel := self updateAccessCharacterFor:displayLabel.
+        ].
+    ].
+
+    menuPanel shown ifTrue:[
+        self fetchImages.
+
+        oldExtent = self displayLabelExtent ifTrue:[
+            self invalidate
+        ] ifFalse:[
+            menuPanel mustRearrange
         ]
-    ] ifFalse:[
-        displayLabel := self updateAccessCharacterFor:displayLabel.
-        w := displayLabel  widthOn:menuPanel.
-        h := displayLabel heightOn:menuPanel.
-    ].
-
-    "/ care for italic fonts - give a few more pixels at the end
-    f := mfont ? (menuPanel font).
-    (f notNil and:[f italic]) ifTrue:[
-        w := w + 2.
-    ].
-    displayLabelExtent := w@h.
-
-    menuPanel setFont:mfont.
-    menuPanel shown ifTrue:[ self fetchImages ].
-
-    oldExtent = displayLabelExtent ifTrue:[
-        self invalidate
-    ] ifFalse:[
-        menuPanel mustRearrange
     ].
 !
 
@@ -5513,7 +5539,7 @@
 preferredExtent
     "compute my preferred extent excluding the shortCutKey and the menu identifier
     "
-    |isVertical icon wIcon isButton
+    |isVertical icon wIcon isButton labelExtent
      x "{ Class:SmallInteger }"
      y "{ Class:SmallInteger }"
      s "{ Class:SmallInteger }"
@@ -5552,8 +5578,10 @@
             x := x + 5.
         ].
     ] ifFalse:[
-        x := x + displayLabelExtent x.
-        y := y + displayLabelExtent y.
+        labelExtent := self displayLabelExtent.
+
+        x := x + labelExtent x.
+        y := y + labelExtent y.
 
         isButton ifFalse:[
             menuPanel showSeparatingLines ifTrue:[
@@ -5966,6 +5994,18 @@
 
 !MenuPanel::Item methodsFor:'change & update'!
 
+fontChanged
+    "called whenever the font changed
+    "
+    displayLabel notNil ifTrue:[
+        displayLabelExtent := nil.
+
+        subMenu notNil ifTrue:[
+            subMenu font:(menuPanel font).
+        ].
+    ].
+!
+
 update:something with:aParameter from:changedObject
 
     |form rect|
@@ -6354,7 +6394,7 @@
 drawRawLabel:aLabel atX:x yOffset:yOffset paint:fg
     "draw a labeled entry; no button, no separator.
     "
-    |mfont fontAscent
+    |mfont labelExtent
      y  "{ Class:SmallInteger }"
      y0 "{ Class:SmallInteger }"
      x0 "{ Class:SmallInteger }"
@@ -6363,8 +6403,9 @@
     mfont := menuPanel setFont:(self font).
     "/ fontAscent := menuPanel font ascent.
     menuPanel paint:fg.
-
-    y := layout top + (layout height - displayLabelExtent y // 2) + yOffset.
+    labelExtent := self displayLabelExtent.
+
+    y := layout top + (layout height - labelExtent y // 2) + yOffset.
 "/  menuPanel centerItems ifTrue:[self halt].
     aLabel isArray ifFalse:[
         y := y + (aLabel ascentOn:menuPanel).
@@ -6381,7 +6422,7 @@
 "/                ] ifTrue:[
 "/                    y0 := y
 "/                ].
-                x0 := x + (displayLabelExtent x - (el widthOn:menuPanel) // 2).
+                x0 := x + (labelExtent x - (el widthOn:menuPanel) // 2).
                 el displayOn:menuPanel x:x0 y:y0.
                 y := y + 1 + (el heightOn:menuPanel)
             ] ifFalse:[
@@ -7440,7 +7481,7 @@
 !MenuPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.379 2004-01-30 13:01:03 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.380 2004-02-01 11:49:59 ca Exp $'
 ! !
 
 MenuPanel initialize!