Author: rolf
Date: 2007-07-20 06:20:59 -0400 (Fri, 20 Jul 2007)
New Revision: 82347

Modified:
   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:
* PropertyGrid.cs: PropertyToolBar: Redraw the entire toolbar when it's
  resized, fixes part of #79829 (vertical lines in toolbar).
  PropertyGrid: Refactored Populate* to something that's easier to
  follow at least for me, as well as splitting it up into several new
  methods, required to update only subitems when something has
  changed by a popup editor or listbox. Don't use events to check
  when any values are changed, since the events are unreliable (we're
  changing the objects the events are registered with, and if the
  event handling requires the objects to be immutable (objects stored
  in hashtables for instance), the events will never be raised).
* PropertyGridView.cs: Call PropertyGrid.PropertyValueChangedInternal
  everytime we change a value, since events are unreliable.
  DropDownButtonClicked: For the same reason don't compare objects to
  check if it has changed or not, it would require all objects to
  derive Equals. Fix dialog location on windows, MS is doing weird
  things when creating parented forms.
* GridEntry.cs: Add a SelectedObject setter.

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-07-20 09:49:09 UTC (rev 82346)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-07-20 10:20:59 UTC (rev 82347)
@@ -1,3 +1,23 @@
+2007-07-20  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
+
+       * PropertyGrid.cs: PropertyToolBar: Redraw the entire toolbar when it's
+         resized, fixes part of #79829 (vertical lines in toolbar).
+         PropertyGrid: Refactored Populate* to something that's easier to
+         follow at least for me, as well as splitting it up into several new
+         methods, required to update only subitems when something has
+         changed by a popup editor or listbox. Don't use events to check
+         when any values are changed, since the events are unreliable (we're
+         changing the objects the events are registered with, and if the
+         event handling requires the objects to be immutable (objects stored
+         in hashtables for instance), the events will never be raised).
+       * PropertyGridView.cs: Call PropertyGrid.PropertyValueChangedInternal
+         everytime we change a value, since events are unreliable.
+         DropDownButtonClicked: For the same reason don't compare objects to
+         check if it has changed or not, it would require all objects to
+         derive Equals. Fix dialog location on windows, MS is doing weird
+         things when creating parented forms.
+       * GridEntry.cs: Add a SelectedObject setter.
+
 2007-07-19  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * TreeNode.cs: Add some corcompare attributes.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs     
2007-07-20 09:49:09 UTC (rev 82346)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/GridEntry.cs     
2007-07-20 10:20:59 UTC (rev 82347)
@@ -203,6 +203,9 @@
                        get {
                                return selected_objects;
                        }
+                       set {
+                               selected_objects = value;
+                       }
                }
 
                internal override int Top {

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs  
2007-07-20 09:49:09 UTC (rev 82346)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGrid.cs  
2007-07-20 10:20:59 UTC (rev 82347)
@@ -523,24 +523,13 @@
                                                
this.help_description_label.Text = 
selected_grid_item.PropertyDescriptor.Description;
 
                                        current_property_value = value.Value;
-                                       if (oldItem != null && 
oldItem.PropertyDescriptor != null) {
-                                               for (int i = 0; i < 
((GridEntry)oldItem).SelectedObjects.Length; i++) {
-                                                       object target = 
GetTarget (oldItem, i);
-                                                       
oldItem.PropertyDescriptor.RemoveValueChanged (target, new EventHandler 
(HandlePropertyValueChanged));
-                                               }
-                                       }
-                                       if 
(selected_grid_item.PropertyDescriptor != null) {
-                                               for (int i = 0; i < 
((GridEntry)selected_grid_item).SelectedObjects.Length; i++) {
-                                                       object target = 
GetTarget (selected_grid_item, i);
-                                                       
selected_grid_item.PropertyDescriptor.AddValueChanged (target, new EventHandler 
(HandlePropertyValueChanged));
-                                               }
-                                       }
                                }
                        }
                }
 
-               private void HandlePropertyValueChanged(object sender, 
EventArgs e) {
-                       OnPropertyValueChanged(new 
PropertyValueChangedEventArgs( selected_grid_item, current_property_value));
+               internal void PropertyValueChangedInternal () {
+                       OnPropertyValueChanged (new 
PropertyValueChangedEventArgs (selected_grid_item, current_property_value));
+                       PopulateSubGridItemsFromProperties (SelectedGridItem as 
GridEntry);
                }
 
                [DefaultValue(null)]
@@ -1185,16 +1174,43 @@
                                root_grid_item = new RootGridEntry 
(property_grid_view,
                                                                    
selected_objects.Length > 1 ? selected_objects : selected_objects[0]);
                                                                           
-                               PopulateMergedGridItems (selected_objects, 
root_grid_item.GridItems, true, root_grid_item);
+                               PopulateMergedGridItems (selected_objects, 
true, root_grid_item as GridEntry);
                        } else {
                                root_grid_item = null;
                        }
                }
 
-               private void PopulateMergedGridItems (object[] objs, 
GridItemCollection grid_item_coll, bool recurse, GridItem parent_grid_item)
+               private bool IsPropertyVisible (PropertyDescriptor property, 
bool mergable)
                {
+                       if (property == null)
+                               return false;
+                               
+                       if (!property.IsBrowsable)
+                               return false;
+                               
+                       if (mergable) {
+                               MergablePropertyAttribute attrib = 
property.Attributes [typeof (MergablePropertyAttribute)] as 
MergablePropertyAttribute;
+                               if (attrib != null && !attrib.AllowMerge)
+                                       return false;
+                       }
+                       
+                       EditorBrowsableAttribute browsable = 
property.Attributes [typeof (EditorBrowsableAttribute)] as 
EditorBrowsableAttribute;
+                       if (browsable != null && (browsable.State == 
EditorBrowsableState.Advanced || browsable.State == 
EditorBrowsableState.Never)) {
+                               return false;
+                       }
+                       
+                       return true;
+               }
+
+               private void PopulateMergedGridItems (object [] objs, bool 
recurse, GridEntry parent_grid_item)
+               {
                        ArrayList intersection = null;
 
+                       if (parent_grid_item == null)
+                               return;
+
+                       GridItemCollection grid_item_coll = 
parent_grid_item.GridItems;
+
                        for (int i = 0; i < objs.Length; i ++) {
                                if (objs [i] == null)
                                        continue;
@@ -1206,9 +1222,11 @@
                                   since that type lacks an override for 
IsDefaultAttribute, and for some reason the
                                   BrowsableAttribute.Yes filter wasn't working 
*/
                                PropertyDescriptorCollection properties = null;
+                               ICustomTypeDescriptor descriptor;
 
-                               if (typeof 
(ICustomTypeDescriptor).IsAssignableFrom (type)) {
-                                       properties = 
((ICustomTypeDescriptor)objs[i]).GetProperties ();
+                               descriptor = objs [i] as ICustomTypeDescriptor;
+                               if (descriptor != null) {
+                                       properties = descriptor.GetProperties 
();
                                }
                                if (properties == null) {
                                        TypeConverter cvt = 
TypeDescriptor.GetConverter (objs[i]);
@@ -1220,72 +1238,103 @@
 
                                foreach (PropertyDescriptor p in (i == 0 ? 
(ICollection)properties : (ICollection)intersection)) {
                                        PropertyDescriptor property = (i == 0 ? 
p : properties [p.Name]);
-                                       if (property == null) {
-                                               /* since the property doesn't 
exist in at least one of the other types, 
-                                                  exclude it */
-                                       }
-                                       else if (!property.IsBrowsable
-                                           || (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,
-                                                  excluded it */
-                                       }
-                                       else {
-                                               Type p_type = p.ComponentType;
-                                               Type property_type = 
property.ComponentType;
+                                       
+                                       if (!IsPropertyVisible (property, 
objs.Length > 1))
+                                               continue;
+                                               
+                                       Type p_type = p.ComponentType;
+                                       Type property_type = 
property.ComponentType;
 
-                                               if (p_type.IsAssignableFrom 
(type))
-                                                       new_intersection.Add 
(p);
-                                               else if 
(property_type.IsAssignableFrom (p_type))
-                                                       new_intersection.Add 
(property);
-                                       }
+                                       if (p_type.IsAssignableFrom (type))
+                                               new_intersection.Add (p);
+                                       else if (property_type.IsAssignableFrom 
(p_type))
+                                               new_intersection.Add (property);
                                }
 
                                intersection = new_intersection;
                        }
 
                        if (intersection != null && intersection.Count > 0)
-                               PopulateGridItemsFromProperties (objs, 
intersection, grid_item_coll, recurse, parent_grid_item);
+                               PopulateGridItemsFromProperties (objs, 
intersection, recurse, parent_grid_item);
                }
 
-               private void PopulateGridItemsFromProperties (object[] objs, 
ArrayList properties,
-                                                             
GridItemCollection grid_item_coll, bool recurse, GridItem parent_grid_item) {
+               private void PopulateGridItemsFromProperties (object[] objs, 
ArrayList properties, bool recurse, GridEntry parent_grid_item)
+               {
+                       
+                       GridItemCollection grid_item_coll = 
parent_grid_item.GridItems;
+
                        foreach (PropertyDescriptor property in properties) {
-
-                               GridEntry grid_entry = new GridEntry 
(property_grid_view, objs, property);
+                               GridEntry grid_entry;
+                               grid_entry = grid_item_coll [property.Name] as 
GridEntry;
+                               if (grid_entry == null) {
+                                       grid_entry = new GridEntry 
(property_grid_view, objs, property);
+                               } else {
+                                       grid_entry.SelectedObjects = objs;
+                               }
+                                       
                                grid_entry.SetParent (parent_grid_item);
+                               
+                               bool categorized = false, show = true;
+                                       
                                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.SetParent 
((GridEntry)parent_grid_item);
-                                       }
+                                       categorized = false;
+                               } else if (property_sort == 
PropertySort.Categorized || property_sort == 
PropertySort.CategorizedAlphabetical) {
+                                       categorized = parent_grid_item == 
root_grid_item;
+                               } else {
+                                       show = false;
                                }
-                               else if (property_sort == 
PropertySort.Categorized || property_sort == 
PropertySort.CategorizedAlphabetical) {
-
-                                       string category = property.Category;
-                                       CategoryGridEntry cat_item = 
grid_item_coll[category] as CategoryGridEntry;
-                                       if (cat_item == null) {
-                                               cat_item = new 
CategoryGridEntry (property_grid_view, category);
-                                               cat_item.SetParent 
(parent_grid_item);
-                                               grid_item_coll.Add (category, 
cat_item);
+                               
+                               
+                               if (show) {
+                                       if (categorized) {
+                                               string category = 
property.Category;
+                                               CategoryGridEntry cat_item = 
grid_item_coll [category] as CategoryGridEntry;
+                                               if (cat_item == null) {
+                                                       cat_item = new 
CategoryGridEntry (property_grid_view, category);
+                                                       cat_item.SetParent 
(parent_grid_item);
+                                                       grid_item_coll.Add 
(category, cat_item);
+                                               }
+                                               if (cat_item.GridItems 
[property.Name] == null) {
+                                                       cat_item.GridItems.Add 
(property.Name, grid_entry);
+                                                       grid_entry.SetParent 
(cat_item);
+                                               }
+                                       } else {
+                                               if (grid_item_coll 
[property.Name] == null) {
+                                                       grid_item_coll.Add 
(property.Name, grid_entry);
+                                                       grid_entry.SetParent 
(parent_grid_item);
+                                               }
                                        }
-                                       if (cat_item.GridItems[property.Name] 
== null) {
-                                               
cat_item.GridItems.Add(property.Name,grid_entry);
-                                               grid_entry.SetParent (cat_item);
-                                       }
                                }
 
-                               if (recurse && property.Converter != null && 
property.Converter.GetPropertiesSupported()) {
-                                       object[] subobjs = new 
object[objs.Length];
-                                       for (int i = 0; i < objs.Length; i ++)
-                                               subobjs[i] = property.GetValue 
(objs[i]);
-                                       PopulateMergedGridItems (subobjs, 
grid_entry.GridItems, false, grid_entry);
+                               if (recurse) {
+                                       PopulateSubGridItemsFromProperties 
(grid_entry);
                                }
                                grid_entry.Expanded = false;
                        }
                }
 
+               private void PopulateSubGridItemsFromProperties (GridEntry 
grid_entry)
+               {
+                       if (grid_entry == null)
+                               return;
+
+                       if (grid_entry.SelectedObjects == null)
+                               return;
+
+                       PropertyDescriptor property = 
grid_entry.PropertyDescriptor;
+
+                       if (property.Converter == null || 
!property.Converter.GetPropertiesSupported ())
+                               return;
+
+                       object [] objs = grid_entry.SelectedObjects;
+                       object [] subobjs = new object [objs.Length];
+                       
+                       for (int i = 0; i < objs.Length; i++)
+                               subobjs [i] = property.GetValue (objs [i]);
+                       
+                       PopulateMergedGridItems (subobjs, true, grid_entry);
+               }
+
                private void help_panel_Paint(object sender, PaintEventArgs e) {
                        
e.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(help_panel.BackColor),
 help_panel.ClientRectangle );
                        e.Graphics.DrawRectangle(SystemPens.ControlDark, 
0,0,help_panel.Width-1,help_panel.Height-1 );
@@ -1352,7 +1401,13 @@
                
                // needed! this little helper makes it possible to draw a 
different toolbar border
                // and toolbar backcolor in ThemeWin32Classic
-               internal class PropertyToolBar : ToolBar {}
+               internal class PropertyToolBar : ToolBar 
+               {
+                       public PropertyToolBar ()
+                       {
+                               SetStyle (ControlStyles.ResizeRedraw, true);
+                       }
+               }
 
 
                [MonoTODO ("not sure what this class does, but it's listed as a 
type converter for a property in this class, and this causes problems if it's 
not present")]

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs  
    2007-07-20 09:49:09 UTC (rev 82346)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs  
    2007-07-20 10:20:59 UTC (rev 82347)
@@ -742,8 +742,8 @@
                                                        Console.WriteLine("No 
converter for type {0}",desc.PropertyType);
                                                }
                                        }
-                                       catch (Exception) {
-                                               Console.WriteLine("Error 
converting string");
+                                       catch (Exception ex) {
+                                               Console.WriteLine("Error 
converting string: " + ex.Message);
                                        }
                                }
                        }
@@ -812,6 +812,8 @@
                                object target = property_grid.GetTarget 
(property_grid.SelectedGridItem, i);
                                desc.SetValue(target, newVal);
                        }
+
+                       property_grid.PropertyValueChangedInternal ();
                }
 
                private void DropDownButtonClicked (object sender, EventArgs e) 
{
@@ -863,9 +865,8 @@
                                
(ITypeDescriptorContext)property_grid.SelectedGridItem,
                                service_container,
                                initial_value);
-                       if (!Object.Equals (value, initial_value)) {
-                               SetPropertyValue (value);
-                       }
+
+                       SetPropertyValue (value);
                }
                
                private void DialogButtonClicked(object sender, EventArgs e) {
@@ -1047,17 +1048,23 @@
 
                        Form owner = FindForm ();
 
+                       Point location;
                        dropdown_form.Size = control.Size;
                        control.Dock = DockStyle.Fill;
                        dropdown_form.Controls.Clear();
                        dropdown_form.Controls.Add(control);
-                       dropdown_form.Location = PointToScreen(new 
Point(SplitterLocation,grid_textbox.Location.Y+row_height));
+                       dropdown_form.Location = PointToScreen (new Point 
(SplitterLocation, grid_textbox.Location.Y + row_height));
+                       location = dropdown_form.Location;
+
                        dropdown_form.Width = ClientRectangle.Width - 
SplitterLocation - (vbar.Visible ? vbar.Width : 0);
 
                        owner.AddOwnedForm (dropdown_form);
 
                        dropdown_form.Show();
 
+                       if (dropdown_form.Location != location) {
+                               dropdown_form.Location = location;
+                       }
                        if (block) {
                                System.Windows.Forms.MSG msg = new MSG();
                                queue_id = 
XplatUI.StartLoop(Thread.CurrentThread);
@@ -1076,6 +1083,8 @@
                                        XplatUI.TranslateMessage(ref msg);
                                        XplatUI.DispatchMessage(ref msg);
                                }
+
+                               property_grid.PropertyValueChangedInternal ();
                        }
                }
 

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

Reply via email to