focusView handling
authorca
Wed, 08 Nov 2006 16:25:51 +0100
changeset 3142 4f1c952048c5
parent 3141 095e746ebc1d
child 3143 645efaba917a
focusView handling
MenuPanel.st
--- a/MenuPanel.st	Wed Nov 08 14:55:26 2006 +0100
+++ b/MenuPanel.st	Wed Nov 08 16:25:51 2006 +0100
@@ -808,11 +808,16 @@
 accept:anItem 
     "this is the topMenu: accept item "
 
-    |item tgState itemIdx recv panel masterGroup winGrp acceptAction|
+    |item tgState itemIdx recv panel masterGroup winGrp acceptAction focusView|
 
     self superMenu notNil ifTrue:[
         ^ self topMenu accept:anItem
     ].
+    prevFocusView ~~ self ifTrue:[
+        focusView := prevFocusView.
+    ].
+    prevFocusView := nil.
+
     self openDelayed:nil.
     self scrollActivity stop.
     self selection:nil.
@@ -826,13 +831,18 @@
     ].
     self doUngrab:true.
 
+    winGrp := self windowGroup.
+    winGrp isNil ifTrue:[focusView := nil].
+
     self isPopUpView ifFalse:[
         self do:[:el| el updateIndicators].
-        self windowGroup processExposeEvents.
+        winGrp notNil ifTrue:[
+            winGrp processExposeEvents.
+        ].
     ] ifTrue:[
         self unmap.
         self device sync. "/ round trip - all expose events are now received
-        (winGrp := self windowGroup) notNil ifTrue:[
+        winGrp notNil ifTrue:[
             "/ give expose event a chance to arrive
             [shown and:[realized]] whileTrue:[
                 winGrp processExposeEventsFor:self
@@ -844,8 +854,11 @@
         masterGroup notNil ifTrue:[masterGroup processExposeEvents].
     ].
 
-    acceptAction := [   
-                        self accept:item index:itemIdx toggle:tgState receiver:recv.
+    acceptAction := [   self accept:item index:itemIdx toggle:tgState receiver:recv.
+
+                        focusView notNil ifTrue:[
+                            self windowGroup focusView:focusView.
+                        ].
                     ].
 
     (item notNil 
@@ -3112,6 +3125,10 @@
         ^ super dispatchEvent:ev withFocusOn:focusView delegate:false.
     ].
 
+    (superMenu isNil and:[ev isButtonPressEvent]) ifTrue:[
+        focusView ~~ self ifTrue:[prevFocusView := focusView].
+    ].
+
     "/ situation: we get a buttonPress, set implicitGrab (for scrollbars etc.)
     "/ but never get the buttonRelease, since someone else (a popUp) grabbed the
     "/ pointer in the meantime, and has eaten the release event ... (double-sigh)
@@ -3547,6 +3564,13 @@
         ]
     ].            
     super hasKeyboardFocus:aBoolean.
+!
+
+showFocus:focusByTab
+    focusByTab == true ifTrue:[
+        prevFocusView := nil.
+    ].
+    super showFocus:focusByTab.
 ! !
 
 !MenuPanel methodsFor:'grabbing'!
@@ -3602,12 +3626,14 @@
 grabMouseAndKeyboard
     "get exclusive access to pointer and keyboard"
 
-    |windowGroup sensor|
-
-    windowGroup := self windowGroup.
-    (realized and:[windowGroup notNil]) ifTrue:[
-        prevFocusView := windowGroup focusView.
-
+    |winGroup sensor|
+
+    winGroup := self windowGroup.
+
+    (realized and:[winGroup notNil]) ifTrue:[
+        prevFocusView isNil ifTrue:[
+             prevFocusView := winGroup focusView.
+        ].
         sensor := self sensor.
         device activePointerGrab ~~ self ifTrue:[
             sensor flushMotionEventsFor:nil.
@@ -3772,7 +3798,7 @@
     self removeDependencies.
 
     super destroy.
-    superMenu := nil.
+    prevFocusView := superMenu := nil.
     shadowView notNil ifTrue:[shadowView destroy].
 
     "Modified: / 15.11.2001 / 17:08:45 / cg"
@@ -3966,7 +3992,7 @@
 "/    self isPopUpView ifTrue:[
 "/         self doUngrab:(superMenu isNil)
 "/    ].
-
+    prevFocusView := nil.
     super unmap.
     shadowView notNil ifTrue:[shadowView unmap].
 !
@@ -7699,7 +7725,7 @@
 !MenuPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.436 2006-11-07 10:10:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.437 2006-11-08 15:25:51 ca Exp $'
 ! !
 
 MenuPanel initialize!