WindowSensor.st
changeset 1790 a7f42261ab45
parent 1734 78fe033bd947
child 1791 d7b59bf5e9da
--- a/WindowSensor.st	Sat Jun 28 13:47:03 1997 +0200
+++ b/WindowSensor.st	Sat Jun 28 16:24:48 1997 +0200
@@ -501,18 +501,44 @@
     self flushUserEventsFor:aView.
 !
 
+flushEventsFor:aView inQueue:anEventQueue and:aCondition
+    "throw away all pending damage events for aView, 
+     for which aCondition returns true.
+     Or any view for which aCondition returns true, if the argument is nil. 
+     A helper for the various flush entries."
+
+    |nEvent "{ Class: SmallInteger }"
+     anEvent|
+
+    accessLock critical:[
+        damage notNil ifTrue:[
+            nEvent := anEventQueue size.
+            1 to:nEvent do:[:index |
+                anEvent := anEventQueue at:index.
+                anEvent notNil ifTrue:[
+                    (aView isNil or:[anEvent view == aView]) ifTrue:[
+                        (aCondition value:anEvent) ifTrue:[
+                            anEventQueue at:index put:nil
+                        ]
+                    ]
+                ]
+            ]
+        ].
+    ]
+
+    "Created: 28.6.1997 / 16:11:35 / cg"
+    "Modified: 28.6.1997 / 16:18:23 / cg"
+!
+
 flushExposeEvents
     "throw away all pending expose events; this
      can be done after a full redraw (or in views, which are
      doing full redraws anly)"
 
-    self flushExposeEventsFor:nil.
-
-"/    (damage isNil or:[damage size > 0]) ifTrue:[
-"/        damage := OrderedCollection new
-"/    ].
-
-    "Modified: 8.2.1997 / 15:13:21 / cg"
+    self
+        flushEventsFor:nil inQueue:damage and:[:event | event isDamage].
+
+    "Modified: 28.6.1997 / 16:12:05 / cg"
 !
 
 flushExposeEventsFor:aView
@@ -522,26 +548,10 @@
      (or in views, which are always doing full redraws -
       instead of drawing the clip-area only)"
 
-    |nEvent "{ Class: SmallInteger }"
-     anEvent|
-
-    accessLock critical:[
-        damage notNil ifTrue:[
-            nEvent := damage size.
-            1 to:nEvent do:[:index |
-                anEvent := damage at:index.
-                anEvent notNil ifTrue:[
-                    anEvent isDamage ifTrue:[
-                        (aView isNil or:[anEvent view == aView]) ifTrue:[
-                            damage at:index put:nil
-                        ]
-                    ]
-                ]
-            ]
-        ].
-    ]
-
-    "Modified: 8.2.1997 / 15:10:37 / cg"
+    self
+        flushEventsFor:aView inQueue:damage and:[:event | event isDamage].
+
+    "Modified: 28.6.1997 / 16:12:15 / cg"
 !
 
 flushKeyboard
@@ -554,52 +564,22 @@
     "throw away all pending keyboard events for aView, 
      or any view, if the argument is nil." 
 
-    |nEvent "{ Class: SmallInteger }"|
-
-    accessLock critical:[
-	mouseAndKeyboard notNil ifTrue:[
-	    nEvent := mouseAndKeyboard size.
-	    1 to:nEvent do:[:i |
-		|anEvent|
-
-		anEvent := mouseAndKeyboard at:i.
-		(anEvent notNil and:[anEvent isKeyEvent]) ifTrue:[
-		    (aView isNil or:[anEvent view == aView]) ifTrue:[
-			mouseAndKeyboard at:i put:nil
-		    ]
-		]
-	    ]
-	].
-    ]
-
-    "Modified: 18.1.1997 / 14:01:04 / cg"
+    self
+        flushEventsFor:aView inQueue:mouseAndKeyboard 
+        and:[:event | event isKeyEvent]
+
+    "Modified: 28.6.1997 / 16:13:23 / cg"
 !
 
 flushMotionEventsFor:aView
     "throw away all pending motion events for aView, 
      or for any view, if the argument is nil." 
 
-    |nEvent "{ Class: SmallInteger }"|
-
-    accessLock critical:[
-        mouseAndKeyboard notNil ifTrue:[
-            nEvent := mouseAndKeyboard size.
-            1 to:nEvent do:[:i |
-                |anEvent|
-
-                anEvent := mouseAndKeyboard at:i.
-                anEvent notNil ifTrue:[
-                    (aView isNil or:[anEvent view == aView]) ifTrue:[
-                        anEvent isButtonMotionEvent ifTrue:[
-                            mouseAndKeyboard at:i put:nil
-                        ]
-                    ]
-                ]
-            ]
-        ].
-    ].
-
-    "Modified: 18.1.1997 / 14:01:17 / cg"
+    self
+        flushEventsFor:aView inQueue:mouseAndKeyboard 
+        and:[:event | event isButtonMotionEvent]
+
+    "Modified: 28.6.1997 / 16:13:39 / cg"
 !
 
 flushUserEvents
@@ -616,27 +596,11 @@
     "throw away all pending user events for aView, 
      or for any view, if the argument is nil." 
 
-    |nEvent "{ Class: SmallInteger }"|
-
-    accessLock critical:[
-	mouseAndKeyboard notNil ifTrue:[
-	    nEvent := mouseAndKeyboard size.
-	    1 to:nEvent do:[:i |
-		|anEvent|
-
-		anEvent := mouseAndKeyboard at:i.
-		anEvent notNil ifTrue:[
-		    (aView isNil or:[anEvent view == aView]) ifTrue:[
-			anEvent isUserEvent ifTrue:[
-			    mouseAndKeyboard at:i put:nil
-			]
-		    ]
-		]
-	    ]
-	].
-    ].
-
-    "Modified: 18.1.1997 / 14:01:17 / cg"
+    self
+        flushEventsFor:aView inQueue:mouseAndKeyboard 
+        and:[:event | event isUserEvent]
+
+    "Modified: 28.6.1997 / 16:13:55 / cg"
 ! !
 
 !WindowSensor methodsFor:'event processing'!
@@ -1757,7 +1721,8 @@
 initialize
     "initialize the event queues to empty"
 
-    accessLock := Semaphore forMutualExclusion name:'WSensor ev-q accessLock'.
+    accessLock := RecursionLock new.
+    accessLock name:'WSensor ev-q accessLock'.
 
     damage := OrderedCollection new.
     mouseAndKeyboard := OrderedCollection new.
@@ -1772,7 +1737,7 @@
     shiftDown := ctrlDown := altDown := metaDown := false.
     leftButtonDown := middleButtonDown := rightButtonDown := false.
 
-    "Modified: 18.1.1997 / 15:30:20 / cg"
+    "Modified: 28.6.1997 / 16:22:16 / cg"
 !
 
 reinitialize
@@ -2241,7 +2206,7 @@
      Do not use this in your applications; polling the sensor is
      bad style."
 
-    self waitButton.
+    self waitButton.
     ^self waitNoButton
 
     "Created: 10.2.1997 / 13:31:09 / cg"
@@ -2338,6 +2303,6 @@
 !WindowSensor class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WindowSensor.st,v 1.101 1997-05-20 20:13:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WindowSensor.st,v 1.102 1997-06-28 14:24:48 cg Exp $'
 ! !
 WindowSensor initialize!