Author: andreia
Date: 2006-11-10 10:11:26 -0500 (Fri, 10 Nov 2006)
New Revision: 67668

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Button.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
   trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FocusTest.cs
Log:
* Button.cs: only perform click when button is Selectable (so as 
not to activate default buttons when they're disabled)

* Control.cs: Rewrite of the SelectNextControl and related 
methods. HandleClick now selects next control if the current one
is being disabled.

* Form.cs: OnActivated selects next active control only if Load 
has already occurred. If Load hasn't run, there's no point in 
selecting here, Load might change the state of controls.

* FocusTest.cs: Tests marked as working again for these fixes

2006-11-10  Andreia Gaita  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Button.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Button.cs        
2006-11-10 14:25:36 UTC (rev 67667)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Button.cs        
2006-11-10 15:11:26 UTC (rev 67668)
@@ -75,7 +75,8 @@
                }
 
                public void PerformClick() {                    // 
IButtonControl
-                       OnClick(EventArgs.Empty);
+                       if (CanSelect)
+                               OnClick(EventArgs.Empty);
                }
 
                public override string ToString() {

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-10 14:25:36 UTC (rev 67667)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-10 15:11:26 UTC (rev 67668)
@@ -1,3 +1,18 @@
+2006-11-10  Andreia Gaita  <[EMAIL PROTECTED]>
+
+       * Button.cs: only perform click when button is Selectable (so as 
+       not to activate default buttons when they're disabled)
+       
+       * Control.cs: Rewrite of the SelectNextControl and related 
+       methods. HandleClick now selects next control if the current one
+       is being disabled.
+       
+       * Form.cs: OnActivated selects next active control only if Load 
+       has already occurred. If Load hasn't run, there's no point in 
+       selecting here, Load might change the state of controls.
+       
+       * FocusTest.cs: Tests marked as working again for these fixes
+
 2006-11-10  Chris Toshok  <[EMAIL PROTECTED]>
 
        * XplatUIX11.cs: a couple of fixes.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2006-11-10 14:25:36 UTC (rev 67667)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs       
2006-11-10 15:11:26 UTC (rev 67668)
@@ -33,6 +33,7 @@
 // COMPLETE 
 
 #undef DebugRecreate
+#undef DebugFocus
 
 using System;
 using System.ComponentModel;
@@ -1197,30 +1198,27 @@
 
                private static Control FindControlForward(Control container, 
Control start) {
                        Control found;
-                       Control p;
 
                        found = null;
 
-                       if (start != null) {
-                               if (start.child_controls != null && 
start.child_controls.Count > 0 &&
-                                       !((start is IContainerControl) && 
start.GetStyle(ControlStyles.ContainerControl))) {
-                                       found = FindControlForward(start, null);
-                                       if (found != null) {
-                                               return found;
-                                       }
-                               }
+                       if (start == null) {
+                               return FindFlatForward(container, start);
+                       }
 
-                               p = start.parent;
-                               while (p != container) {
-                                       found = FindFlatForward(p, start);
+                       if (start.child_controls != null && 
start.child_controls.Count > 0 && 
+                               (start == container || !((start is 
IContainerControl) &&  start.GetStyle(ControlStyles.ContainerControl)))) {
+                               return FindControlForward(start, null);
+                       }
+                       else {
+                               while (start != container) {
+                                       found = FindFlatForward(start.parent, 
start);
                                        if (found != null) {
                                                return found;
                                        }
-                                       start = p;
-                                       p = p.parent;
+                                       start = start.parent;
                                }
                        }
-                       return FindFlatForward(container, start);
+                       return null;
                }
 
                private static Control FindFlatBackward(Control container, 
Control start) {
@@ -1244,27 +1242,55 @@
                                index++;
                        }
 
-                       for (int i = end-1, pos = -1; i >= 0; i--) {
+                       bool hit = false;
+                                       
+                       for (int i = end - 1; i >= 0; i--) {
                                if (start == container.child_controls[i]) {
-                                       pos = i;
+                                       hit = true;
                                        continue;
                                }
 
-                               if (found == null) {
-                                       if 
(container.child_controls[i].tab_index < index || 
-                                               (pos > -1 && pos > i && 
container.child_controls[i].tab_index == index)) {
+                               if (found == null || found.tab_index < 
container.child_controls[i].tab_index) {
+                                       if 
(container.child_controls[i].tab_index < index || (hit && 
container.child_controls[i].tab_index == index))
                                                found = 
container.child_controls[i];
-                                       }
-                               } else if (found.tab_index < 
container.child_controls[i].tab_index) {
-                                       if 
(container.child_controls[i].tab_index < index) {
-                                               found = 
container.child_controls[i];
-                                       }
+
                                }
                        }
                        return found;
                }
 
                private static Control FindControlBackward(Control container, 
Control start) {
+
+                       Control found = null;
+
+                       if (start == null) {
+                               found = FindFlatBackward(container, start);
+                       }
+                       else if (start != container) {
+                               if (start.parent != null) {
+                                       found = FindFlatBackward(start.parent, 
start);
+
+                                       if (found == null) {
+                                               if (start.parent != container)
+                                                       return start.parent;
+                                               return null;
+                                       }
+                               }
+                       }
+               
+                       if (found == null || start.parent == null)
+                               found = start;
+
+                       while (found != null && (found == container || 
(!((found is IContainerControl) && 
found.GetStyle(ControlStyles.ContainerControl))) &&
+                               found.child_controls != null && 
found.child_controls.Count > 0)) {
+//                             while (ctl.child_controls != null && 
ctl.child_controls.Count > 0 && 
+//                                     (ctl == this || (!((ctl is 
IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))))) {
+                               found = FindFlatBackward(found, null);
+                       }
+
+                       return found;
+
+/*
                        Control found;
 
                        found = null;
@@ -1289,8 +1315,8 @@
                                        }
                                }
                        }
-
                        return found;
+*/                     
                }
 
                internal virtual void HandleClick(int clicks, MouseEventArgs 
me) {
@@ -1959,15 +1985,13 @@
                        }
 
                        set {
-                               if (Enabled == value) {
-                                       is_enabled = value;
-                                       return;
-                               }
 
+                               bool old_value = is_enabled;
+
                                is_enabled = value;
+                               if (old_value != value && !value && 
this.has_focus)
+                                       SelectNextControl(this, true, true, 
true, true);
 
-                               // FIXME - we need to switch focus to next 
control if we're disabling the focused control
-
                                OnEnabledChanged (EventArgs.Empty);             
                
                        }
                }
@@ -2817,30 +2841,21 @@
 
                public Control GetNextControl(Control ctl, bool forward) {
 
-                       if (ctl != null && this != ctl) {
-                               if (!ctl.CanSelect || 
-                                       ((parent == null) && (ctl is 
IContainerControl) && ctl.GetStyle(ControlStyles.ContainerControl))
-                                  ) {
-                                       if (forward) {
-                                               return FindFlatForward(this, 
ctl);
-                                       } else {
-                                               return FindFlatBackward(this, 
ctl);
-                                       }
-                               }
-                       }
-
-                       // If ctl is not contained by this, we start at the 
first child of this
                        if (!this.Contains(ctl)) {
-                               ctl = null;
+                               ctl = this;
                        }
 
-                       // Search through our controls, starting at ctl, 
stepping into children as we encounter them
-                       // try to find the control with the tabindex closest to 
our own, or, if we're looking into
-                       // child controls, the one with the smallest tabindex
                        if (forward) {
-                               return FindControlForward(this, ctl);
+                               ctl = FindControlForward(this, ctl);
                        }
-                       return FindControlBackward(this, ctl);
+                       else {
+                               ctl = FindControlBackward(this, ctl);
+                       }
+
+                       if (ctl != this) {
+                               return ctl;
+                       }
+                       return null;
                }
 
 #if NET_2_0
@@ -3226,9 +3241,25 @@
                        Select(false, false);
                }
 
+#if DebugFocus
+               private void printTree(Control c, string t) {
+                       foreach(Control i in c.child_controls) {
+                               Console.WriteLine("{2}{0}.TabIndex={1}", i, 
i.tab_index, t);
+                               printTree(i, t+"\t");
+                       }
+               }
+#endif
                public bool SelectNextControl(Control ctl, bool forward, bool 
tabStopOnly, bool nested, bool wrap) {
                        Control c;
 
+#if DebugFocus
+                       Console.WriteLine("{0}", this.FindForm());
+                       printTree(this, "\t");
+#endif
+
+                       if (!this.Contains(ctl) || (!nested && (ctl.parent != 
this))) {
+                               ctl = null;
+                       }
                        c = ctl;
                        do {
                                c = GetNextControl(c, forward);

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2006-11-10 14:25:36 UTC (rev 67667)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Form.cs  
2006-11-10 15:11:26 UTC (rev 67668)
@@ -78,6 +78,7 @@
                internal ApplicationContext     context;
                Color                           transparency_key;
                internal MenuTracker            active_tracker;
+               private bool                    is_loaded;
 
                #endregion      // Local Variables
 
@@ -1424,7 +1425,8 @@
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnActivated(EventArgs e)
                {
-                       SelectActiveControl ();
+                       if (is_loaded)
+                               SelectActiveControl ();
 
                        if (Activated != null) {
                                Activated(this, e);
@@ -1527,6 +1529,7 @@
                                                break;
                                }
                        }
+                       is_loaded = true;
                }
 
                [EditorBrowsable(EditorBrowsableState.Advanced)]

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FocusTest.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FocusTest.cs    
    2006-11-10 14:25:36 UTC (rev 67667)
+++ 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/FocusTest.cs    
    2006-11-10 15:11:26 UTC (rev 67668)
@@ -601,7 +601,6 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetNextGroupBoxControlFlat ()
                {
                        Form form = new Form ();
@@ -640,7 +639,6 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetNextControlFromTabControl ()
                {
                        Form form = new Form ();
@@ -670,7 +668,6 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void GetNextControlFromTabControl2 () {
                        Form form = new Form ();
                        form.ShowInTaskbar = false;
@@ -816,7 +813,6 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void FocusSetsActive ()
                {
                        Form form = new Form ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to