flixiblized for better radioButton
authorClaus Gittinger <cg@exept.de>
Mon, 03 Nov 1997 16:25:29 +0100
changeset 1385 691d891fa440
parent 1384 e4acb2c5b10b
child 1386 e0c08a81b559
flixiblized for better radioButton
Toggle.st
--- a/Toggle.st	Mon Nov 03 16:24:30 1997 +0100
+++ b/Toggle.st	Mon Nov 03 16:25:29 1997 +0100
@@ -10,11 +10,9 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.2.1 on 20-oct-1997 at 3:15:58 pm'                  !
-
 Button subclass:#Toggle
 	instanceVariableNames:'showLamp lampColor lampWidth lampHeight'
-	classVariableNames:'DefaultShowLamp DefaultLampColor'
+	classVariableNames:'DefaultShowLamp DefaultLampColor LampInset'
 	poolDictionaries:''
 	category:'Views-Interactors'
 !
@@ -369,8 +367,9 @@
 
     DefaultShowLamp := StyleSheet at:'toggle.showLamp' default:false.
     DefaultLampColor := StyleSheet colorAt:'toggle.lampColor' default:Color yellow.
+    LampInset := 1 "2".
 
-    "Modified: 20.10.1997 / 15:15:35 / cg"
+    "Modified: / 3.11.1997 / 11:42:19 / cg"
 ! !
 
 !Toggle methodsFor:'accessing-look'!
@@ -450,6 +449,8 @@
 initStyle
     "setup viewStyle specifics"
 
+    |mm|
+
     super initStyle.
 
     showLamp := DefaultShowLamp.
@@ -463,10 +464,12 @@
     ].
 
     lampColor := DefaultLampColor.
-    lampWidth := (device horizontalPixelPerMillimeter * 1.8) rounded.
-    lampHeight := (device verticalPixelPerMillimeter * 3.5) rounded.
+    mm := StyleSheet at:'toggle.lampWidthMM' default:1.5.
+    lampWidth := (device horizontalPixelPerMillimeter * mm) rounded.
+    mm := StyleSheet at:'toggle.lampHeightMM' default:3.0.
+    lampHeight := (device verticalPixelPerMillimeter * mm) rounded.
 
-    "Modified: 22.1.1997 / 11:57:55 / cg"
+    "Modified: / 3.11.1997 / 02:22:02 / cg"
 ! !
 
 !Toggle methodsFor:'private'!
@@ -477,8 +480,10 @@
 
     super computeLabelOrigin.
     showLamp ifTrue:[
-	labelOriginX := labelOriginX + hSpace + lampWidth + hSpace.
+        labelOriginX := labelOriginX + hSpace + (self lampImageWidth) + hSpace.
     ]
+
+    "Modified: / 3.11.1997 / 14:27:03 / cg"
 !
 
 computeLabelSize
@@ -486,9 +491,11 @@
 
     super computeLabelSize.
     showLamp ifTrue:[
-	labelWidth := labelWidth + hSpace + lampWidth + hSpace.
-	labelHeight := labelHeight max: lampHeight
+        labelWidth := labelWidth + hSpace + (self lampImageWidth) + hSpace.
+        labelHeight := labelHeight max: self lampImageHeight
     ]
+
+    "Modified: / 3.11.1997 / 14:26:54 / cg"
 !
 
 getValueFromModel
@@ -508,6 +515,18 @@
     ].
 
     "Created: 14.11.1995 / 21:08:43 / cg"
+!
+
+lampImageHeight
+    ^ lampHeight
+
+    "Created: / 3.11.1997 / 14:24:47 / cg"
+!
+
+lampImageWidth
+    ^ lampWidth
+
+    "Created: / 3.11.1997 / 14:25:35 / cg"
 ! !
 
 !Toggle methodsFor:'queries'!
@@ -528,41 +547,61 @@
     showLamp ifTrue:[
         "/ add some space for the lamp.
 
-        x := pref x + lampWidth + hSpace.
-        y := pref y max:(lampHeight).
+        x := pref x + (self lampImageWidth) + hSpace.
+        y := pref y max:(self lampImageHeight).
         pref := x @ y.
     ].
     ^ pref
 
-    "Modified: 18.2.1997 / 13:12:51 / cg"
+    "Modified: / 3.11.1997 / 14:26:41 / cg"
 ! !
 
 !Toggle methodsFor:'redrawing'!
 
+drawToggleImage
+    "drawing of the lamp is done here."
+
+    |x y clr l2|
+
+    showLamp ifTrue:[
+        x := hSpace + margin.
+        y := (height - self lampImageHeight) // 2.
+        self 
+            drawEdgesForX:x y:y 
+            width:(self lampImageWidth) 
+            height:(self lampImageHeight)
+            level:-1.
+        controller pressed ifTrue:[
+            clr := lampColor.
+        ] ifFalse:[
+            clr := bgColor.
+        ].
+        self paint:clr.
+        l2 := LampInset*2.
+        self 
+            fillRectangleX:x+LampInset y:y+LampInset 
+            width:(self lampImageWidth) - l2 
+            height:(self lampImageHeight) - l2
+    ]
+
+    "Created: / 3.11.1997 / 12:12:07 / cg"
+    "Modified: / 3.11.1997 / 14:26:33 / cg"
+!
+
 drawWith:fg and:bg
     "redraw myself with fg/bg. Use super to draw the label, 
      drawing of the lamp is done here."
 
-    |x y clr|
-
+    shown ifFalse:[^ self].
     super drawWith:fg and:bg.   "this draws the text"
 
-    showLamp ifTrue:[
-	x := hSpace + margin.
-	y := (height - lampHeight) // 2.
-	self drawEdgesForX:x y:y width:lampWidth height:lampHeight level:-1.
-	controller pressed ifTrue:[
-	    clr := lampColor.
-	] ifFalse:[
-	    clr := bgColor.
-	].
-	self paint:clr.
-	self fillRectangleX:x+2 y:y+2 width:lampWidth - 4 height:lampHeight - 4
-    ]
+    self drawToggleImage.
+
+    "Modified: / 3.11.1997 / 13:19:32 / cg"
 ! !
 
 !Toggle class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.38 1997-10-21 18:03:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Toggle.st,v 1.39 1997-11-03 15:25:29 cg Exp $'
 ! !