Author: toshok
Date: 2006-11-06 19:56:22 -0500 (Mon, 06 Nov 2006)
New Revision: 67423

Modified:
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CategoryGridEntry.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs
   
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs
Log:
2006-11-06  Chris Toshok  <[EMAIL PROTECTED]>

        * PropertyGrid.cs:
        - set the initial SelectedGridItem if we can.

        - Exclude non-mergable properties only if we're merging > 1
        object.  Merging 1 object isn't really merging, obviously.

        - Handle PropertySort.NoSort just like Alphabetical, which is
        wrong of course, but at least gets things on the screen.
        
        * PropertyGridView.cs:
        - Add method "FindFirstItem" which finds the first property grid
        item, so we can select it by default.

        - make use of GridEntry.CanResetValue.

        - Don't call RedrawBelowItemOnExpansion here anymore, the
        individual GridEntry's will do that.

        - Remove the ITypeDescriptorContextImpl internal class.
        
        * GridEntry.cs:
        - this class needs to implement ITypeDescriptorContext, as it's
        what MS's PropertyDescriptorGridEntry does, which means we can
        remove the ITypeDescriptorContextImpl internal class from
        PropertyGrid.cs.  This fixes the crashing portion of bug #79829.

        - keep a reference to our PropertyGridView, and move the call to
        RedrawBelowItemOnExpansion here from PGV.  This means
        programmaticly setting Expanded actually does something visible.

        - add a CanResetValue() function which takes into account our
        possibly multiple "selected_objects" in the merged case.  Shifting
        PropertyGridView to use this method fixes another unreported
        crasher found running the test for #79829.

        - when Top or Bounds is updated, make sure the PropertyGridTextBox
        is updated to reflect this.

        * CategoryGridEntry.cs: the ctor takes the PGV now.
        


Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CategoryGridEntry.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CategoryGridEntry.cs 
    2006-11-07 00:16:02 UTC (rev 67422)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/CategoryGridEntry.cs 
    2006-11-07 00:56:22 UTC (rev 67423)
@@ -9,7 +9,8 @@
        internal class CategoryGridEntry : GridEntry
        {
                private string label;
-               public CategoryGridEntry(string category)
+               public CategoryGridEntry(PropertyGridView owner, string 
category)
+                       : base (owner)
                {
                        label = category;
                }

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-07 00:16:02 UTC (rev 67422)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-11-07 00:56:22 UTC (rev 67423)
@@ -1,3 +1,45 @@
+2006-11-06  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * PropertyGrid.cs:
+       - set the initial SelectedGridItem if we can.
+
+       - Exclude non-mergable properties only if we're merging > 1
+       object.  Merging 1 object isn't really merging, obviously.
+
+       - Handle PropertySort.NoSort just like Alphabetical, which is
+       wrong of course, but at least gets things on the screen.
+       
+       * PropertyGridView.cs:
+       - Add method "FindFirstItem" which finds the first property grid
+       item, so we can select it by default.
+
+       - make use of GridEntry.CanResetValue.
+
+       - Don't call RedrawBelowItemOnExpansion here anymore, the
+       individual GridEntry's will do that.
+
+       - Remove the ITypeDescriptorContextImpl internal class.
+       
+       * GridEntry.cs:
+       - this class needs to implement ITypeDescriptorContext, as it's
+       what MS's PropertyDescriptorGridEntry does, which means we can
+       remove the ITypeDescriptorContextImpl internal class from
+       PropertyGrid.cs.  This fixes the crashing portion of bug #79829.
+
+       - keep a reference to our PropertyGridView, and move the call to
+       RedrawBelowItemOnExpansion here from PGV.  This means
+       programmaticly setting Expanded actually does something visible.
+
+       - add a CanResetValue() function which takes into account our
+       possibly multiple "selected_objects" in the merged case.  Shifting
+       PropertyGridView to use this method fixes another unreported
+       crasher found running the test for #79829.
+
+       - when Top or Bounds is updated, make sure the PropertyGridTextBox
+       is updated to reflect this.
+
+       * CategoryGridEntry.cs: the ctor takes the PGV now.
+       
 2006-11-06  Jackson Harper  <[EMAIL PROTECTED]>
 
        * TextControl.cs: These are 1 based.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs     
2006-11-07 00:16:02 UTC (rev 67422)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs     
2006-11-07 00:56:22 UTC (rev 67423)
@@ -32,7 +32,7 @@
 
 namespace System.Windows.Forms.PropertyGridInternal
 {
-       internal class GridEntry : GridItem
+       internal class GridEntry : GridItem, ITypeDescriptorContext
        {
                #region Local Variables
                private bool expanded = true;
@@ -45,17 +45,20 @@
                private int top;
                private Rectangle plus_minus_bounds;
                private Rectangle bounds;
+               private PropertyGridView property_grid_view;
                #endregion      // Local Variables
 
                #region  Contructors
-               public GridEntry() : base() {
+               protected GridEntry (PropertyGridView view)
+               {
+                       property_grid_view = view;
                        plus_minus_bounds = new Rectangle(0,0,0,0);
                        bounds = new Rectangle(0,0,0,0);
                        top = -1;
                        grid_items = new GridItemCollection();
                }
 
-               public GridEntry(object[] objs, PropertyDescriptor prop_desc) : 
this() {
+               public GridEntry(PropertyGridView view, object[] objs, 
PropertyDescriptor prop_desc) : this (view) {
                        selected_objects = objs;
                        property_descriptor = prop_desc;
                }
@@ -76,7 +79,11 @@
                        }
 
                        set {
+                               if (expanded == value)
+                                       return;
+
                                expanded = value;
+                               property_grid_view.RedrawBelowItemOnExpansion 
(this);
                        }
                }
 
@@ -115,6 +122,14 @@
                        }
                }
 
+               public bool CanResetValue ()
+               {
+                       if (Value == null) /* not sure if this is always 
right.. */
+                               return false;
+
+                       return 
PropertyDescriptor.CanResetValue(selected_objects[0]);
+               }
+
                public override object Value
                {
                        get {
@@ -143,6 +158,47 @@
                }
                #endregion      // Public Instance Methods
 
+               #region ITypeDescriptorContext Members
+
+               void ITypeDescriptorContext.OnComponentChanged() {
+                       // TODO:  Add SystemComp.OnComponentChanged 
implementation
+               }
+
+               [MonoTODO ("this is broken, as PropertyGridView doesn't 
implement IContainer")]
+               IContainer ITypeDescriptorContext.Container {
+                       get {
+                               return property_grid_view as IContainer;
+                       }
+               }
+
+               bool ITypeDescriptorContext.OnComponentChanging() {
+                       // TODO:  Add SystemComp.OnComponentChanging 
implementation
+                       return false;
+               }
+
+               object ITypeDescriptorContext.Instance {
+                       get {
+                               return Value;
+                       }
+               }
+
+               PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor {
+                       get {
+                               return PropertyDescriptor;
+                       }
+               }
+
+               #endregion
+
+               #region IServiceProvider Members
+
+               object IServiceProvider.GetService(Type serviceType) {
+                       // TODO:  Add SystemComp.GetService implementation
+                       return null;
+               }
+
+               #endregion
+
                internal object[] SelectedObjects {
                        get {
                                return selected_objects;
@@ -154,7 +210,12 @@
                                return top;
                        }
                        set {
+                               if (top == value)
+                                       return;
+
                                top = value;
+                               if 
(property_grid_view.property_grid.SelectedGridItem == this)
+                                       property_grid_view.grid_textbox_Show 
(this);
                        }
                }
 
@@ -175,7 +236,12 @@
                        }
                        set
                        {
+                               if (bounds == value)
+                                       return;
+
                                bounds = value;
+                               if 
(property_grid_view.property_grid.SelectedGridItem == this)
+                                       property_grid_view.grid_textbox_Show 
(this);
                        }
                }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs  
2006-11-07 00:16:02 UTC (rev 67422)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs  
2006-11-07 00:56:22 UTC (rev 67423)
@@ -530,6 +530,10 @@
 
                                RefreshTabs(PropertyTabScope.Component);
                                ReflectObjects();
+                               if (grid_items.Count > 0) {
+                                       /* find the first non category grid 
item and select it */
+                                       SelectedGridItem = 
property_grid_view.FindFirstItem (grid_items);
+                               }
                                property_grid_view.Refresh();
                                OnSelectedObjectsChanged (EventArgs.Empty);
                        }
@@ -992,7 +996,7 @@
                                                   exclude it */
                                        }
                                        else if (!property.IsBrowsable
-                                           || (objs.Length > 0 && 
property.Attributes.Contains (MergablePropertyAttribute.No))
+                                           || (objs.Length > 1 && 
property.Attributes.Contains (MergablePropertyAttribute.No))
                                            || property.Attributes.Contains 
(new EditorBrowsableAttribute (EditorBrowsableState.Never))
                                            || property.Attributes.Contains 
(new EditorBrowsableAttribute (EditorBrowsableState.Advanced))) {
                                                /* if the property isn't 
supposed to be displayed in the merged view,
@@ -1020,9 +1024,9 @@
                                                              
GridItemCollection grid_item_coll, bool recurse, GridItem parent_grid_item) {
                        foreach (PropertyDescriptor property in properties) {
 
-                               GridEntry grid_entry = new GridEntry (objs, 
property);
+                               GridEntry grid_entry = new GridEntry 
(property_grid_view, objs, property);
                                grid_entry.SetParent (parent_grid_item);
-                               if (property_sort == PropertySort.Alphabetical 
|| !recurse) {
+                               if (property_sort == PropertySort.Alphabetical 
|| /* XXX */property_sort == PropertySort.NoSort || !recurse) {
                                        if (grid_item_coll[property.Name] == 
null) {
                                                
grid_item_coll.Add(property.Name,grid_entry);
                                                grid_entry.SetUIParent 
((GridEntry)parent_grid_item);
@@ -1033,7 +1037,7 @@
                                        string category = property.Category;
                                        CategoryGridEntry cat_item = 
grid_item_coll[category] as CategoryGridEntry;
                                        if (cat_item == null) {
-                                               cat_item = new 
CategoryGridEntry(category);
+                                               cat_item = new 
CategoryGridEntry(property_grid_view, category);
                                                cat_item.SetParent 
(parent_grid_item);
                                                cat_item.SetUIParent 
((GridEntry)parent_grid_item);
                                                
grid_item_coll.Add(category,cat_item);

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs  
    2006-11-07 00:16:02 UTC (rev 67422)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs  
    2006-11-07 00:56:22 UTC (rev 67423)
@@ -48,7 +48,7 @@
                private const int RESIZE_WIDTH = 3;
                private const int BUTTON_WIDTH = 25;
                private PropertyGridTextBox grid_textbox;
-               private PropertyGrid property_grid;
+               internal PropertyGrid property_grid;
                private bool resizing_grid;
                private int open_grid_item_count = -1;
                private int skipped_grid_items;
@@ -152,8 +152,9 @@
                        }
                }
 
-               void RedrawBelowItemOnExpansion (GridItem item)
+               public void RedrawBelowItemOnExpansion (GridItem item)
                {
+                       grid_textbox_Hide ();
 #if DOUBLEBUFFER
                        Invalidate(new Rectangle (0, item.Top, Width, Height - 
item.Top));
 #else
@@ -179,12 +180,12 @@
                        InvalidateGridItem (item);
                        Update();
 #endif
+                       grid_textbox_Show (property_grid.SelectedGridItem);
                }
 
                protected override void OnDoubleClick(EventArgs e) {
                        if (property_grid.SelectedGridItem.Expandable) {
                                property_grid.SelectedGridItem.Expanded = 
!property_grid.SelectedGridItem.Expanded;
-                               RedrawBelowItemOnExpansion 
(property_grid.SelectedGridItem);
                        }
                        else {
                                ToggleValue();
@@ -245,7 +246,6 @@
                                        if (foundItem.Expandable) {
                                                if (e.X >=3 && e.X <= 11 && 
(e.Y % row_height >= row_height/2-2 && e.Y % row_height <= row_height/2+4)) {
                                                        foundItem.Expanded = 
!foundItem.Expanded;
-                                                       
RedrawBelowItemOnExpansion (foundItem);
                                                }
                                        }
                                        this.property_grid.SelectedGridItem = 
foundItem;
@@ -335,6 +335,22 @@
                        }
                }
 
+               public GridItem FindFirstItem (GridItemCollection items)
+               {
+                       foreach (GridItem item in items) {
+                               if (item.GridItemType == GridItemType.Property)
+                                       return item;
+
+                               if (item.GridItems.Count > 0) {
+                                       GridItem subitem = FindFirstItem 
(item.GridItems);
+                                       if (subitem != null)
+                                               return subitem;
+                               }
+                       }
+
+                       return null;
+               }
+
                private GridEntry MoveUpFromItem (GridEntry item, int up_count)
                {
                        GridItemCollection items;
@@ -428,7 +444,6 @@
                                           otherwise, act just like the user 
pressed up */
                                        if (selectedItem.Expandable && 
selectedItem.Expanded) {
                                                selectedItem.Expanded = false;
-                                               RedrawBelowItemOnExpansion 
(property_grid.SelectedGridItem);
                                                e.Handled = true;
                                                break;
                                        }
@@ -448,7 +463,6 @@
                                           otherwise, act just like the user 
pressed down */
                                        if (selectedItem.Expandable && 
!selectedItem.Expanded) {
                                                selectedItem.Expanded = true;
-                                               RedrawBelowItemOnExpansion 
(property_grid.SelectedGridItem);
                                                e.Handled = true;
                                                break;
                                        }
@@ -459,7 +473,6 @@
                                /* toggle the expanded state of the selected 
item */
                                if (selectedItem.Expandable) {
                                        selectedItem.Expanded = 
!selectedItem.Expanded;
-                                       RedrawBelowItemOnExpansion 
(property_grid.SelectedGridItem);
                                }
                                e.Handled = true;
                                break;
@@ -627,8 +640,7 @@
                                        try {
                                                
editor.PaintValue(grid_item.Value, pevent.Graphics, new 
Rectangle(SplitterLocation+3,rect.Y+3, 19, row_height-5));
                                        }
-                                       catch (Exception ex) {
-                                               System.Console.WriteLine(ex);
+                                       catch (Exception) {
                                        }
                                        xLoc += 27;
                                }
@@ -639,9 +651,9 @@
                                                Brush brush;
 
                                                string value = 
grid_item.PropertyDescriptor.Converter.ConvertToString(grid_item.Value);
-                                               if 
(grid_item.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
+                                               if 
(((GridEntry)grid_item).CanResetValue ())
                                                        font = bold_font;
-                               
+
                                                brush = 
SystemBrushes.WindowText;
                                                if 
(grid_item.PropertyDescriptor.IsReadOnly
                                                    && !grid_item.Expandable)
@@ -653,7 +665,7 @@
                                                                                
          ClientRectangle.Width-(xLoc), row_height),string_format);
                                        }
                                        else {
-                                               System.Console.WriteLine("No 
converter for type {0}",grid_item.PropertyDescriptor.PropertyType);
+                                               Console.WriteLine("No converter 
for type {0}",grid_item.PropertyDescriptor.PropertyType);
                                        }
 
                                }
@@ -726,7 +738,7 @@
                                                        
SetPropertyValue(desc.Converter.ConvertFromString(grid_textbox.Text));
                                                }
                                                else {
-                                                       
System.Console.WriteLine("No converter for type {0}",desc.PropertyType);
+                                                       Console.WriteLine("No 
converter for type {0}",desc.PropertyType);
                                                }
                                        }
                                        catch (Exception) {
@@ -847,7 +859,7 @@
                        service_container.AddService (typeof 
(IWindowsFormsEditorService), this);
                        object initial_value = 
property_grid.SelectedGridItem.Value;
                        object value = editor.EditValue (
-                               new ITypeDescriptorContextImpl 
(this.property_grid),
+                               
(ITypeDescriptorContext)property_grid.SelectedGridItem,
                                service_container,
                                initial_value);
                        if (!Object.Equals (value, initial_value)) {
@@ -892,14 +904,14 @@
                        Invalidate();
                }
 
-               private void grid_textbox_Show (GridItem forItem)
+               internal void grid_textbox_Show (GridItem forItem)
                {
                        if (forItem == null || forItem.PropertyDescriptor == 
null)
                                return;
 
                        SuspendLayout ();
 
-                       if 
(forItem.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
+                       if (((GridEntry)forItem).CanResetValue ())
                                grid_textbox.Font = bold_font;
                        else
                                grid_textbox.Font = this.Font;
@@ -936,7 +948,7 @@
                                                }
                                        }
                                        else {
-                                               
System.Console.WriteLine("Converter not available for type 
{0}",forItem.PropertyDescriptor.PropertyType);
+                                               Console.WriteLine("Converter 
not available for type {0}",forItem.PropertyDescriptor.PropertyType);
                                        }
                                                
                                }
@@ -993,11 +1005,12 @@
 
                        if (e.NewSelection.GridItemType == 
GridItemType.Property) {
                                if (e.NewSelection.PropertyDescriptor != null) {
+
                                        if (e.NewSelection.Value == null)
                                                grid_textbox.Text = "";
                                        else
                                                grid_textbox.Text = 
e.NewSelection.PropertyDescriptor.Converter.ConvertToString(e.NewSelection.Value);
-                                       if 
(e.NewSelection.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
+                                       if 
(((GridEntry)e.NewSelection).CanResetValue ())
                                                grid_textbox.Font = bold_font;
                                        else
                                                grid_textbox.Font = this.Font;
@@ -1013,7 +1026,7 @@
                private void PropertyValueChanged(object s, 
PropertyValueChangedEventArgs e) {
                        if (e.ChangedItem.PropertyDescriptor != null) {
                                grid_textbox.Text = 
e.ChangedItem.PropertyDescriptor.Converter.ConvertToString(e.ChangedItem.Value);
-                               if 
(e.ChangedItem.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
+                               if (((GridEntry)e.ChangedItem).CanResetValue())
                                        grid_textbox.Font = bold_font;
                                else
                                        grid_textbox.Font = this.Font;
@@ -1085,56 +1098,6 @@
 
                #endregion
 
-               #region Internal Classes
-               internal class ITypeDescriptorContextImpl : 
System.ComponentModel.ITypeDescriptorContext {
-                       private PropertyGrid property_grid;
-                       public ITypeDescriptorContextImpl(PropertyGrid 
propertyGrid) {
-                               property_grid = propertyGrid;
-                       }
-                       #region ITypeDescriptorContext Members
-
-                       public void OnComponentChanged() {
-                               // TODO:  Add SystemComp.OnComponentChanged 
implementation
-                       }
-
-                       public IContainer Container {
-                               get {
-                                       return property_grid as IContainer;
-                               }
-                       }
-
-                       public bool OnComponentChanging() {
-                               // TODO:  Add SystemComp.OnComponentChanging 
implementation
-                               return false;
-                       }
-
-                       public object Instance {
-                               get {
-                                       return 
property_grid.SelectedGridItem.Value;
-                               }
-                       }
-
-                       public PropertyDescriptor PropertyDescriptor {
-                               get {
-                                       return 
property_grid.SelectedGridItem.PropertyDescriptor;
-                               }
-                       }
-
-                       #endregion
-
-                       #region IServiceProvider Members
-
-                       public object GetService(Type serviceType) {
-                               // TODO:  Add SystemComp.GetService 
implementation
-                               return null;
-                       }
-
-                       #endregion
-
-               }
-
-
-               
                /*
                        class ComboListBox
                */
@@ -1149,7 +1112,5 @@
                        }
 
                }
-
-               #endregion
        }
 }

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

Reply via email to