Scroller.st
changeset 1794 f3dd5bcc9876
parent 1768 32eb81e67be1
child 1799 7d3daeab6afe
--- a/Scroller.st	Mon Mar 15 11:59:32 1999 +0100
+++ b/Scroller.st	Tue Mar 16 14:04:59 1999 +0100
@@ -19,7 +19,8 @@
 		tallyLevel tallyMarks fixThumbHeight frameBeforeMove ghostColor
 		ghostFrameColor ghostLevel rangeStart rangeEnd rangeStep entered
 		thumbActiveLevel originBeforeMove thumbImage enabled
-		enableChannel keyboardStep'
+		enableChannel keyboardStep autoRepeat repeatBlock
+		initialRepeatDelay repeatDelay'
 	classVariableNames:'HandleShadowForm HandleLightForm DefaultViewBackground
 		DefaultShadowColor DefaultLightColor DefaultThumbColor
 		DefaultThumbShadowColor DefaultThumbLightColor
@@ -1001,6 +1002,20 @@
     "Modified: 8.2.1997 / 15:15:58 / cg"
 ! !
 
+!Scroller methodsFor:'autoRepeat'!
+
+repeatPageDown
+    self pageDown.
+    Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
+
+!
+
+repeatPageUp
+    self pageUp.
+    Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
+
+! !
+
 !Scroller methodsFor:'drawing'!
 
 drawHandleFormAtX:x y:y
@@ -1291,38 +1306,52 @@
     sensor := self sensor.
     (((sensor notNil and:[sensor shiftDown]))
     or:[DefaultMiddleButtonJump and:[button == 2]]) ifTrue:[
-	^ self buttonShiftPress:button x:x y:y
+        ^ self buttonShiftPress:button x:x y:y
     ].
     button ~~ 1 ifTrue:[
-	^ self
+        ^ self
     ].
 
     thumbFrame isNil ifTrue:[
-	self computeThumbFrame.
-	thumbFrame isNil ifTrue:[^ self].
+        self computeThumbFrame.
+        thumbFrame isNil ifTrue:[^ self].
     ].
 
     (orientation == #vertical) ifTrue:[
-	curr := y.
-	limit1 := thumbFrame top.
-	limit2 := thumbFrame bottom
+        curr := y.
+        limit1 := thumbFrame top.
+        limit2 := thumbFrame bottom
     ] ifFalse:[
-	curr := x.
-	limit1 := thumbFrame left.
-	limit2 := thumbFrame right
+        curr := x.
+        limit1 := thumbFrame left.
+        limit2 := thumbFrame right
     ].
 
     (curr < limit1) ifTrue:[
-	"page up/left"
-	self pageUp
+        "page up/left"
+        self pageUp.
+        autoRepeat ifTrue:[
+            repeatBlock notNil ifTrue:[
+                Processor removeTimedBlock:repeatBlock.
+            ].
+            repeatBlock := [self repeatPageUp].
+            Processor addTimedBlock:repeatBlock afterSeconds:initialRepeatDelay
+        ]
     ] ifFalse:[
-	(curr > limit2) ifTrue:[
-	    "page down/right"
-	    self pageDown
-	] ifFalse:[
-	    pressOffset := curr - limit1.
-	    scrolling := true
-	]
+        (curr > limit2) ifTrue:[
+            "page down/right"
+            self pageDown.
+            autoRepeat ifTrue:[
+                repeatBlock notNil ifTrue:[
+                    Processor removeTimedBlock:repeatBlock.
+                ].
+                repeatBlock := [self repeatPageDown].
+                Processor addTimedBlock:repeatBlock afterSeconds:initialRepeatDelay
+            ]
+        ] ifFalse:[
+            pressOffset := curr - limit1.
+            scrolling := true
+        ]
     ].
     self highlightThumbForPointerX:x y:y.
     self changeCursorFor:(x@y).
@@ -1337,38 +1366,43 @@
 
     |rect mustDrawThumb|
 
+    repeatBlock notNil ifTrue:[
+        Processor removeTimedBlock:repeatBlock.
+        repeatBlock := nil
+    ].
+
     (button == 1 or:[DefaultMiddleButtonJump and:[button == 2]])
-	ifFalse:[^ super buttonRelease:button x:x y:y].
+        ifFalse:[^ super buttonRelease:button x:x y:y].
 
     scrolling ifTrue:[
-	scrolling := false.
-	thumbFrame notNil ifTrue:[
-	    mustDrawThumb := false.
+        scrolling := false.
+        thumbFrame notNil ifTrue:[
+            mustDrawThumb := false.
 
-	    frameBeforeMove notNil ifTrue:[
-		rect := frameBeforeMove.
-		frameBeforeMove := nil.
-		self drawThumbBackgroundInX:rect left
-					  y:rect top
-				      width:rect width 
-				     height:rect height.
+            frameBeforeMove notNil ifTrue:[
+                rect := frameBeforeMove.
+                frameBeforeMove := nil.
+                self drawThumbBackgroundInX:rect left
+                                          y:rect top
+                                      width:rect width 
+                                     height:rect height.
 
-		(rect intersects:thumbFrame) ifTrue:[
-		    mustDrawThumb := true.
-		]
-	    ].
-	    thumbLevel ~~ thumbActiveLevel ifTrue:[
-		mustDrawThumb := true
-	    ].
-	    mustDrawThumb ifTrue:[
-		self drawThumb
-	    ].    
+                (rect intersects:thumbFrame) ifTrue:[
+                    mustDrawThumb := true.
+                ]
+            ].
+            thumbLevel ~~ thumbActiveLevel ifTrue:[
+                mustDrawThumb := true
+            ].
+            mustDrawThumb ifTrue:[
+                self drawThumb
+            ].    
 
 "/            scrolling := false.
-	    synchronousOperation ifFalse: [
-		self tellOthers.
-	    ]
-	]
+            synchronousOperation ifFalse: [
+                self tellOthers.
+            ]
+        ]
     ].
     self changeCursorFor:(x@y)
 
@@ -1742,29 +1776,32 @@
 initStyle
     "initialize style dep. stuff"
 
-    <resource: #style (#name)>
+    <resource: #style (#name 
+                       #'scroller.autoRepeat'
+                       #'scroller.initialRepeatDelay'
+                       #'scroller.repeatDelay')>
 
     |nm|
 
     super initStyle.
 
     DefaultViewBackground notNil ifTrue:[
-	viewBackground := DefaultViewBackground onDevice:device.
+        viewBackground := DefaultViewBackground onDevice:device.
     ].
     DefaultShadowColor notNil ifTrue:[
-	shadowColor := DefaultShadowColor onDevice:device.
+        shadowColor := DefaultShadowColor onDevice:device.
     ].
     DefaultLightColor notNil ifTrue:[
-	lightColor := DefaultLightColor onDevice:device.
+        lightColor := DefaultLightColor onDevice:device.
     ].
 
     tallyMarks := DefaultTallyMarks.
     tallyLevel := DefaultTallyLevel.
     DefaultLevel ~~ level ifTrue:[
-	self level:DefaultLevel.
+        self level:DefaultLevel.
     ].
     DefaultBorderWidth ~~ borderWidth ifTrue:[
-	self borderWidth:DefaultBorderWidth.
+        self borderWidth:DefaultBorderWidth.
     ].
     thumbLevel := DefaultThumbLevel.
     thumbActiveLevel := DefaultThumbActiveLevel.
@@ -1773,114 +1810,118 @@
     thumbEdgeStyle := DefaultEdgeStyle.
 
     DefaultGhostColor notNil ifTrue:[
-	ghostColor := DefaultGhostColor onDevice:device.
+        ghostColor := DefaultGhostColor onDevice:device.
     ].
     DefaultGhostFrameColor notNil ifTrue:[
-	ghostFrameColor := DefaultGhostFrameColor onDevice:device.
+        ghostFrameColor := DefaultGhostFrameColor onDevice:device.
     ].
     ghostLevel := DefaultGhostLevel.
 
     DefaultThumbFrameColor notNil ifTrue:[
-	thumbFrameColor := DefaultThumbFrameColor onDevice:device.
+        thumbFrameColor := DefaultThumbFrameColor onDevice:device.
     ].
     DefaultThumbShadowColor notNil ifTrue:[
-	thumbShadowColor := DefaultThumbShadowColor
+        thumbShadowColor := DefaultThumbShadowColor
     ] ifFalse:[
-	thumbShadowColor := shadowColor.
+        thumbShadowColor := shadowColor.
     ].
     DefaultThumbLightColor notNil ifTrue:[
-	thumbLightColor := DefaultThumbLightColor
+        thumbLightColor := DefaultThumbLightColor
     ] ifFalse:[
-	thumbLightColor := lightColor.
+        thumbLightColor := lightColor.
     ].
 
     thumbEdgeStyle notNil ifTrue:[
-	DefaultThumbHalfShadowColor notNil ifTrue:[
-	    thumbHalfShadowColor := DefaultThumbHalfShadowColor
-	].
+        DefaultThumbHalfShadowColor notNil ifTrue:[
+            thumbHalfShadowColor := DefaultThumbHalfShadowColor
+        ].
 
-	DefaultThumbHalfLightColor notNil ifTrue:[
-	    thumbHalfLightColor := DefaultThumbHalfLightColor
-	].
+        DefaultThumbHalfLightColor notNil ifTrue:[
+            thumbHalfLightColor := DefaultThumbHalfLightColor
+        ].
     ].
 
     nm := styleSheet name.
 
     device hasGrayscales ifFalse:[
-	thumbEdgeStyle notNil ifTrue:[
-	    thumbHalfShadowColor := Color darkGray.
-	    thumbHalfLightColor := White
-	].
+        thumbEdgeStyle notNil ifTrue:[
+            thumbHalfShadowColor := Color darkGray.
+            thumbHalfLightColor := White
+        ].
 
-	thumbShadowColor := Black.
+        thumbShadowColor := Black.
 "/        thumbLightColor := White.
 
-	nm = #motif ifTrue:[
-	    DefaultThumbColor isNil ifTrue:[
-		thumbColor := White .
-	    ].
-	]
+        nm = #motif ifTrue:[
+            DefaultThumbColor isNil ifTrue:[
+                thumbColor := White .
+            ].
+        ]
     ].
 
     DefaultThumbColor notNil ifTrue:[
-	thumbColor := DefaultThumbColor onDevice:device
+        thumbColor := DefaultThumbColor onDevice:device
     ] ifFalse:[
-	thumbColor := White.
-	nm ~= #normal ifTrue:[
-	    device hasGrayscales ifFalse:[
-		thumbColor := Color grey
-	    ].
-	].
+        thumbColor := White.
+        nm ~= #normal ifTrue:[
+            device hasGrayscales ifFalse:[
+                thumbColor := Color grey
+            ].
+        ].
     ].
 
     thumbColor := thumbColor on:device.
     thumbShadowColor notNil ifTrue:[
-	thumbShadowColor := thumbShadowColor onDevice:device.
+        thumbShadowColor := thumbShadowColor onDevice:device.
     ].
     thumbLightColor notNil ifTrue:[
-	thumbLightColor := thumbLightColor onDevice:device.
+        thumbLightColor := thumbLightColor onDevice:device.
     ].
     thumbHalfShadowColor notNil ifTrue:[
-	thumbHalfShadowColor := thumbHalfShadowColor onDevice:device.
+        thumbHalfShadowColor := thumbHalfShadowColor onDevice:device.
     ].
     thumbHalfLightColor notNil ifTrue:[
-	thumbHalfLightColor := thumbHalfLightColor onDevice:device.
+        thumbHalfLightColor := thumbHalfLightColor onDevice:device.
     ].
     thumbEdgeStyle notNil ifTrue:[
-	thumbHalfShadowColor isNil ifTrue:[
-	    thumbHalfShadowColor := thumbShadowColor lightened onDevice:device
-	]
+        thumbHalfShadowColor isNil ifTrue:[
+            thumbHalfShadowColor := thumbShadowColor lightened onDevice:device
+        ]
     ].
 
     DefaultThumbEnteredColor notNil ifTrue:[
-	thumbEnteredColor := DefaultThumbEnteredColor onDevice:device.
+        thumbEnteredColor := DefaultThumbEnteredColor onDevice:device.
     ] ifFalse:[
-	thumbEnteredColor := thumbColor.
+        thumbEnteredColor := thumbColor.
     ].
 
     (DefaultThumbEnteredColor notNil or:[NewCursors]) ifTrue:[
-	self enableMotionEvents.
-	self enableEnterLeaveEvents.
+        self enableMotionEvents.
+        self enableEnterLeaveEvents.
     ].
 
     DefaultThumbImage notNil ifTrue:[
-	thumbImage := DefaultThumbImage onDevice:device.
-	fixThumbHeight := true.
+        thumbImage := DefaultThumbImage onDevice:device.
+        fixThumbHeight := true.
     ].
 
     HandleImage notNil ifTrue:[
-	shadowForm := HandleImage onDevice:device.
+        shadowForm := HandleImage onDevice:device.
     ] ifFalse:[
-	nm = #next ifTrue:[
-	    shadowForm := self class handleShadowFormOn:device.
-	    lightForm := self class handleLightFormOn:device
-	] ifFalse:[
-	    shadowForm := lightForm := nil
-	].
+        nm = #next ifTrue:[
+            shadowForm := self class handleShadowFormOn:device.
+            lightForm := self class handleLightFormOn:device
+        ] ifFalse:[
+            shadowForm := lightForm := nil
+        ].
     ].
     drawableId notNil ifTrue:[
-	self computeThumbFrame
-    ]
+        self computeThumbFrame
+    ].
+
+    autoRepeat := styleSheet at:#'scroller.autoRepeat' default:true.
+    initialRepeatDelay := styleSheet at:#'scroller.initialRepeatDelay' default:0.2.
+    repeatDelay := styleSheet at:#'scroller.repeatDelay' default:0.1.
 
     "Modified: / 5.9.1998 / 20:21:41 / cg"
 !
@@ -2269,5 +2310,5 @@
 !Scroller class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Scroller.st,v 1.115 1999-03-07 13:26:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Scroller.st,v 1.116 1999-03-16 13:04:59 cg Exp $'
 ! !