Author: jpobst
Date: 2007-07-19 11:25:14 -0400 (Thu, 19 Jul 2007)
New Revision: 82291

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
Log:
2007-07-19  Jonathan Pobst  <[EMAIL PROTECTED]>

        * ListBox.cs: Implement custom tab offsets.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-07-19 14:52:35 UTC (rev 82290)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-07-19 15:25:14 UTC (rev 82291)
@@ -1,3 +1,7 @@
+2007-07-19  Jonathan Pobst  <[EMAIL PROTECTED]>
+
+       * ListBox.cs: Implement custom tab offsets.
+
 2007-07-18  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * ToolStripContentPanel.cs: Support System renderer.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs       
2007-07-19 14:52:35 UTC (rev 82290)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListBox.cs       
2007-07-19 15:25:14 UTC (rev 82291)
@@ -97,7 +97,9 @@
                private int focused_item = -1;          
                private ObjectCollection items;
 #if NET_2_0
+               private IntegerCollection custom_tab_offsets;
                private Padding padding;
+               private bool use_custom_tab_offsets;
 #endif
 
                public ListBox ()
@@ -141,6 +143,10 @@
                        LostFocus += new EventHandler (OnLostFocus);
                        
                        SetStyle (ControlStyles.UserPaint, false);
+
+#if NET_2_0
+                       custom_tab_offsets = new IntegerCollection (this);
+#endif
                }
 
                #region Events
@@ -284,6 +290,14 @@
                        get { return base.CreateParams;}
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [DesignerSerializationVisibility 
(DesignerSerializationVisibility.Content)]
+               public IntegerCollection CustomTabOffsets {
+                       get { return custom_tab_offsets; }
+               }
+#endif
+
                protected override Size DefaultSize {
                        get { return new Size (120, 96); }
                }
@@ -637,6 +651,19 @@
                        }
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [DefaultValue (false)]
+               public bool UseCustomTabOffsets {
+                       get { return use_custom_tab_offsets; }
+                       set { 
+                               if (use_custom_tab_offsets != value) {
+                                       use_custom_tab_offsets = value;
+                                       CalculateTabStops ();
+                               }
+                        }
+               }
+#endif
                [DefaultValue (true)]
                public bool UseTabStops {
                        get { return use_tabstops; }
@@ -645,12 +672,9 @@
                                if (use_tabstops == value)
                                        return;
 
-                               use_tabstops = value;                           
        
-                               if (use_tabstops)
-                                       StringFormat.SetTabStops (0, new float 
[] {(float)(Font.Height * 3.7)});
-                               else
-                                       StringFormat.SetTabStops (0, new float 
[0]);
-                               base.Refresh ();
+                               use_tabstops = value;
+                               
+                               CalculateTabStops ();
                        }
                }
 
@@ -1112,6 +1136,25 @@
 
                #region Private Methods
 
+               private void CalculateTabStops ()
+               {
+                       if (use_tabstops) {
+#if NET_2_0
+                               if (use_custom_tab_offsets) {
+                                       float[] f = new 
float[custom_tab_offsets.Count];
+                                       custom_tab_offsets.CopyTo (f, 0);
+                                       StringFormat.SetTabStops (0, f);
+                               }
+                               else
+#endif
+                                       StringFormat.SetTabStops (0, new 
float[] { (float)(Font.Height * 3.7) });
+                       }       
+                       else
+                               StringFormat.SetTabStops (0, new float[0]);
+                               
+                       this.Invalidate ();
+               }
+
                private Size canvas_size;
 
                private void LayoutListBox ()
@@ -1934,8 +1977,7 @@
                                                string_format.Alignment = 
StringAlignment.Far;
                                        else
                                                string_format.Alignment = 
StringAlignment.Near;
-                                       if (use_tabstops)
-                                               string_format.SetTabStops (0, 
new float [] {(float)(Font.Height * 3.7)});
+                                       CalculateTabStops ();
                                }
                                return string_format;
                        }
@@ -2081,7 +2123,7 @@
                        
                        public int this [int index] {
                                get { return list[index]; }
-                               set { list[index] = value; }
+                               set { list[index] = value; 
owner.CalculateTabStops (); }
                        }
                        #endregion
 
@@ -2092,6 +2134,7 @@
                                if (!list.Contains (item)) {
                                        list.Add (item);
                                        list.Sort ();
+                                       owner.CalculateTabStops ();
                                }
                                
                                return list.IndexOf (item);
@@ -2118,6 +2161,7 @@
                        public void Clear ()
                        {
                                list.Clear ();
+                               owner.CalculateTabStops ();
                        }
                        
                        public bool Contains (int item)
@@ -2127,7 +2171,8 @@
                        
                        public void CopyTo (Array destination, int index)
                        {
-                               list.CopyTo ((int[])destination, index);
+                               for (int i = index; i < list.Count; i++)
+                                       destination.SetValue (list[i], i);
                        }
                        
                        public int IndexOf (int item)
@@ -2139,12 +2184,14 @@
                        {
                                list.Remove (item);
                                list.Sort ();
+                               owner.CalculateTabStops ();
                        }
                        
                        public void RemoveAt (int index)
                        {
                                list.RemoveAt (index);
                                list.Sort ();
+                               owner.CalculateTabStops ();
                        }
                        #endregion
 

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

Reply via email to