focus handling changed: looking for subviewsInFocusOrder
authorca
Fri, 02 Mar 2007 16:01:47 +0100
changeset 4733 80b915a584ab
parent 4732 b5bdb640655a
child 4734 cad9cacb9cde
focus handling changed: looking for subviewsInFocusOrder
WindowGroup.st
--- a/WindowGroup.st	Fri Mar 02 15:38:18 2007 +0100
+++ b/WindowGroup.st	Fri Mar 02 16:01:47 2007 +0100
@@ -1921,87 +1921,40 @@
 focusNext
     "give focus to next view from focusView or topView
     "
-    |curView oldView nxtView subViews index sequence size|
-
-    oldView := focusView.
+    |curView oldView nxtView myTopViews|
+
+    (myTopViews := topViews) isEmptyOrNil ifTrue:[
+        self setFocusView:nil.
+        ^ self
+    ].
 
     (curView := focusView) isNil ifTrue:[
-        topViews notNil ifTrue:[
-            curView := topViews detect:[:aView|aView shown] ifNone:nil.
-            self setFocusView:curView.
+        myTopViews do:[:aView|
+            (aView shown and:[(nxtView := aView focusNext) notNil]) ifTrue:[
+                ^ self focusView:nxtView byTab:true
+            ].
         ].
-
-        focusView isNil ifTrue:[
-            ^ self
-        ]
-    ] ifFalse:[
-        self setFocusView:nil
+        ^ self
+    ].
+    (nxtView := curView focusNext) notNil ifTrue:[
+        self focusView:nxtView byTab:true.
+        ^ self
     ].
-
-    "/ SUPPORT OLD STUFF
-
-    sequence := curView topView focusSequence.
-    size := sequence size.
-
-    size ~~ 0 ifTrue:[
-        oldView isNil ifTrue:[
-            index := 0
-        ] ifFalse:[
-            index := sequence identityIndexOf:oldView
-        ].
-
-        sequence from:(index + 1) do:[:v|
-            (v shown and:[v enabled]) ifTrue:[
-                ^ self focusView:v byTab:true
-            ]
-        ].
-
-        sequence from:1 to:(index - 1) do:[:v|
-            (v shown and:[v enabled]) ifTrue:[
-                ^ self focusView:v byTab:true
-            ]
+    self setFocusView:nil.
+
+    [   oldView := curView.
+        (curView := curView superView) notNil
+    ] whileTrue:[
+        curView shown ifTrue:[
+            nxtView := curView focusNextChildAfter:oldView.
+            nxtView notNil ifTrue:[
+                ^ self focusView:nxtView byTab:true
+            ].
         ].
     ].
-
-    "/ NEW STUFF
-
-    (nxtView := curView focusNext) notNil ifTrue:[
-        ^ self focusView:nxtView byTab:true
-    ].
-
-
-    [true] whileTrue:[
-        oldView := curView.
-        curView := curView superView.
-
-        curView isNil ifTrue:[
-            focusView notNil ifTrue:[
-                ^ self
-            ].
-            ^ self focusNext
-        ].
-
-        curView shown ifTrue:[
-            subViews := curView subViews.
-            index    := subViews identityIndexOf:oldView.
-
-            index == 0 ifTrue:[
-                "/ should not happen; but who guarantees
-                ^ self
-            ].
-
-            subViews from:(index + 1) do:[:v|
-                v shown ifTrue:[
-                    (v canTab and:[v enabled]) ifTrue:[
-                        ^ self focusView:v byTab:true
-                    ].
-
-                    (nxtView := v focusNext) notNil ifTrue:[
-                        ^ self focusView:nxtView byTab:true
-                    ]
-                ]
-            ]
-        ]
+    "/ ? should tab through the windowGroup ?
+    focusView isNil ifTrue:[
+        self focusNext
     ].
 !
 
@@ -2017,7 +1970,7 @@
 focusPrevious
     "give focus to previous view from focusView or topView
     "
-    |curView oldView nxtView subViews index done sequence size|
+    |curView oldView nxtView subViews done|
 
     (curView := focusView) isNil ifTrue:[
         topViews notNil ifTrue:[
@@ -2026,41 +1979,8 @@
     ].
     curView isNil ifTrue:[^ self].
 
-    "/ SUPPORT OLD STUFF
-
-    sequence := curView topView focusSequence.
-    size := sequence size.
-
-    size ~~ 0 ifTrue:[
-        focusView isNil ifTrue:[
-            index := size + 1
-        ] ifFalse:[
-            index := sequence identityIndexOf:focusView.
-        ].
-
-        sequence from:1 to:(index - 1) reverseDo:[:v|
-            (v shown and:[v enabled]) ifTrue:[
-                ^ self focusView:v byTab:true
-            ]
-        ].
-
-        sequence from:size to:(index + 1) reverseDo:[:v|
-            (v shown and:[v enabled]) ifTrue:[
-                ^ self focusView:v byTab:true
-            ]
-        ].
-
-        sequence from:1 to:(index - 1) do:[:v|
-            (v shown and:[v enabled]) ifTrue:[
-                ^ self focusView:v byTab:true
-            ]
-        ].
-    ].
-
-    "/ NEW STUFF
-
     focusView isNil ifTrue:[
-        subViews := curView subViews.
+        subViews := curView subviewsInFocusOrder.
 
         subViews size ~~ 0 ifTrue:[
             curView := subViews detectLast:[:v|v shown] ifNone:nil
@@ -2070,7 +1990,7 @@
         ].
         done := false.
 
-        [done not and:[(subViews := curView subViews) size ~~ 0]] whileTrue:[
+        [done not and:[(subViews := curView subviewsInFocusOrder) size ~~ 0]] whileTrue:[
             nxtView := subViews detectLast:[:v|v shown] ifNone:nil.
 
             nxtView notNil ifTrue:[curView := nxtView]
@@ -2114,27 +2034,9 @@
         ].
 
         curView shown ifTrue:[
-            subViews := curView subViews.
-            index    := subViews identityIndexOf:oldView.
-
-            index == 0 ifTrue:[
-                "/ should not happen; but who guarantees
-                ^ self
-            ].
-            subViews from:1 to:(index - 1) reverseDo:[:v|
-                v shown ifTrue:[
-                    nxtView := v focusPrevious.
-
-                    nxtView notNil ifTrue:[
-                        ^ self focusView:nxtView byTab:true
-                    ].
-                    (v canTab and:[v enabled]) ifTrue:[
-                        ^ self focusView:v byTab:true
-                    ].
-                ]
-            ].
-            (curView canTab and:[curView enabled]) ifTrue:[
-                ^ self focusView:curView byTab:true
+            nxtView := curView focusPreviousChildBefore:oldView.
+            nxtView notNil ifTrue:[
+                ^ self focusView:nxtView byTab:true
             ].
         ].
     ].
@@ -2186,14 +2088,6 @@
     "Modified: / 20.5.1999 / 18:30:31 / cg"
 !
 
-focusSequence
-    "return my focus sequence for focusNext/focusPrevious.
-     Focus is stepped in the order in which subviews occur in
-     the sequence"
-
-    ^ nil
-!
-
 focusSequence:aSequenceableCollection
     "define the focus sequence for focusNext/focusPrevious.
      Focus is stepped in the order in which subviews occur in
@@ -2787,7 +2681,7 @@
 !WindowGroup class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/WindowGroup.st,v 1.284 2006-11-08 11:18:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/WindowGroup.st,v 1.285 2007-03-02 15:01:47 ca Exp $'
 ! !
 
 WindowGroup initialize!