Pass context information to UITypeEditors
authorJonathan Chambers <joncham@gmail.com>
Wed, 22 Jun 2005 03:28:59 +0000 (03:28 -0000)
committerJonathan Chambers <joncham@gmail.com>
Wed, 22 Jun 2005 03:28:59 +0000 (03:28 -0000)
svn path=/trunk/mcs/; revision=46342

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/PropertyGridView.cs

index 02a24db860ab7be0831b6f7b808e92df6c6252c1..af13eb25611e5318b1d23221aded4f53cd457cff 100644 (file)
@@ -1,3 +1,7 @@
+2005-06-21  Jonathan Chambers <jonathan.chambers@ansys.com>
+       
+       * PropertyGridView.cs: Pass context information to UITypeEditors 
+
 2005-06-21  Peter Bartok  <pbartok@novell.com> 
 
        * TextBoxBase.cs:
index 12fb5dd6559bb3984b869bb4b0972b5c49febcb2..12c36eee986084b58966ef465aff8cde9621b607 100644 (file)
@@ -147,7 +147,8 @@ namespace System.Windows.Forms.PropertyGridInternal
 \r
                protected override void OnMouseMove (MouseEventArgs e) \r
                {\r
-                       if (resizing_grid) {\r
+                       if (resizing_grid) \r
+                       {\r
                                splitter_location = Math.Max(e.X,V_INDENT);\r
                                Refresh();\r
                        }\r
@@ -156,8 +157,10 @@ namespace System.Windows.Forms.PropertyGridInternal
 \r
                private GridItem GetSelectedGridItem (GridItemCollection grid_items, int y) \r
                {\r
-                       foreach (GridItem child_grid_item in grid_items) {\r
-                               if (y > child_grid_item.Top && y < child_grid_item.Top + ROW_HEIGHT) {\r
+                       foreach (GridItem child_grid_item in grid_items) \r
+                       {\r
+                               if (y > child_grid_item.Top && y < child_grid_item.Top + ROW_HEIGHT) \r
+                               {\r
                                        return child_grid_item;\r
                                }\r
                                GridItem foundItem = GetSelectedGridItem(child_grid_item.GridItems, y);\r
@@ -169,10 +172,12 @@ namespace System.Windows.Forms.PropertyGridInternal
 \r
                protected override void OnMouseDown (MouseEventArgs e) \r
                {\r
-                       if (e.X > splitter_location - RESIZE_WIDTH && e.X < splitter_location + RESIZE_WIDTH) {\r
+                       if (e.X > splitter_location - RESIZE_WIDTH && e.X < splitter_location + RESIZE_WIDTH) \r
+                       {\r
                                resizing_grid = true;\r
                        }\r
-                       else {\r
+                       else \r
+                       {\r
                                GridItem foundItem = GetSelectedGridItem(property_grid.grid_items, e.Y);\r
                                \r
                                if (foundItem != null)\r
@@ -317,12 +322,20 @@ namespace System.Windows.Forms.PropertyGridInternal
                                        {
                                                try
                                                {\r
-                                               if (grid_item.PropertyDescriptor.Converter.GetStandardValuesSupported()) \r
-                                               {\r
+                                                       if (grid_item.PropertyDescriptor.Converter != null)\r
+                                                       {\r
+                                                               if (grid_item.PropertyDescriptor.Converter.GetStandardValuesSupported()) \r
+                                                               {\r
                                                        \r
-                                                       grid_textbox.DropDownButtonVisible = true;\r
-                                                       grid_textbox.ReadOnly = true;
-                                               }\r
+                                                                       grid_textbox.DropDownButtonVisible = true;\r
+                                                                       grid_textbox.ReadOnly = true;
+                                                               }\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               System.Console.WriteLine("Converter not available for type {0}",grid_item.PropertyDescriptor.PropertyType);\r
+                                                       }\r
+                                               \r
                                                }
                                                catch (Exception ex)
                                                {
@@ -343,20 +356,29 @@ namespace System.Windows.Forms.PropertyGridInternal
                                        catch (Exception ex)\r
                                        {\r
                                                System.Console.WriteLine(ex.Message);\r
+                                               System.Console.WriteLine("Paint Value failed for type {0}",grid_item.PropertyDescriptor.PropertyType);\r
                                                // design time stuff is not playing nice\r
                                        }\r
                                        xLoc += 27;\r
                                }\r
 \r
                                Font font = this.Font;\r
-                               try {
-                               string value = grid_item.PropertyDescriptor.Converter.ConvertToString(grid_item.Value);\r
-                               if (grid_item.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))\r
-                                       font = new Font(font, FontStyle.Bold);\r
+                               try \r
+                               {
+                                       if (grid_item.PropertyDescriptor.Converter != null)
+                                       {
+                                               string value = grid_item.PropertyDescriptor.Converter.ConvertToString(grid_item.Value);\r
+                                               if (grid_item.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))\r
+                                                       font = new Font(font, FontStyle.Bold);\r
                                
-                               pevent.Graphics.DrawString(value,font,SystemBrushes.WindowText,new RectangleF(xLoc,rect.Y+2, ClientRectangle.Width-(xLoc), ROW_HEIGHT));\r
+                                               pevent.Graphics.DrawString(value,font,SystemBrushes.WindowText,new RectangleF(xLoc,rect.Y+2, ClientRectangle.Width-(xLoc), ROW_HEIGHT));\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               System.Console.WriteLine("No converter for type {0}",grid_item.PropertyDescriptor.PropertyType);\r
+                                       }\r
 \r
-}
+                               }
                                catch (Exception e)
                                {
                                }
@@ -419,13 +441,21 @@ namespace System.Windows.Forms.PropertyGridInternal
 \r
                private void TextBoxValidating (object sender, CancelEventArgs e) \r
                {\r
-                       if (this.property_grid.SelectedGridItem != null) {\r
+                       if (this.property_grid.SelectedGridItem != null) \r
+                       {\r
                                PropertyDescriptor desc = property_grid.SelectedGridItem.PropertyDescriptor;\r
-                               if (desc != null) {\r
+                               if (desc != null) \r
+                               {\r
                                        try \r
                                        {\r
-                                               \r
-                                               SetPropertyValue(desc.Converter.ConvertFromString(grid_textbox.Text));\r
+                                               if (desc.Converter != null)\r
+                                               {\r
+                                                       SetPropertyValue(desc.Converter.ConvertFromString(grid_textbox.Text));\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       System.Console.WriteLine("No converter for type {0}",desc.PropertyType);\r
+                                               }\r
                                        }\r
                                        catch (Exception ex)\r
                                        {\r
@@ -449,9 +479,11 @@ namespace System.Windows.Forms.PropertyGridInternal
 \r
                private void listBox_SelectedIndexChanged (object sender, EventArgs e) \r
                {\r
-                       if (this.property_grid.SelectedGridItem != null) {\r
+                       if (this.property_grid.SelectedGridItem != null) \r
+                       {\r
                                PropertyDescriptor desc = property_grid.SelectedGridItem.PropertyDescriptor;\r
-                               if (desc != null) {\r
+                               if (desc != null) \r
+                               {\r
                                        SetPropertyValue(((ListBox)sender).SelectedItem);\r
                                }\r
                        }\r
@@ -494,7 +526,7 @@ namespace System.Windows.Forms.PropertyGridInternal
                                UITypeEditor editor = (UITypeEditor)property_grid.SelectedGridItem.PropertyDescriptor.GetEditor(typeof(UITypeEditor));\r
                                System.ComponentModel.Design.ServiceContainer service_container = new System.ComponentModel.Design.ServiceContainer();\r
                                service_container.AddService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService), this);\r
-                               SetPropertyValue(editor.EditValue(null, service_container,property_grid.SelectedGridItem.Value));\r
+                               SetPropertyValue(editor.EditValue(new ITypeDescriptorContextImpl(this.property_grid), service_container,property_grid.SelectedGridItem.Value));\r
                        }\r
                }\r
                \r
@@ -538,13 +570,13 @@ namespace System.Windows.Forms.PropertyGridInternal
                                        XplatUI.ScrollWindow(Handle, 0, -ROW_HEIGHT, false);\r
                                        Invalidate(ClientRectangle);\r
                                        break;\r
-                               /*case ScrollEventType.ThumbTrack:\r
-                                       XplatUI.ScrollWindow(Handle, 0, -(vbar.Value-e.NewValue), false);\r
-                                       Invalidate(ClientRectangle);\r
-                                       break;\r
-                               case ScrollEventType.ThumbPosition:\r
-                                       Invalidate(ClientRectangle);\r
-                                       break;*/\r
+                                       /*case ScrollEventType.ThumbTrack:\r
+                                               XplatUI.ScrollWindow(Handle, 0, -(vbar.Value-e.NewValue), false);\r
+                                               Invalidate(ClientRectangle);\r
+                                               break;\r
+                                       case ScrollEventType.ThumbPosition:\r
+                                               Invalidate(ClientRectangle);\r
+                                               break;*/\r
                        }\r
                }\r
 \r
@@ -555,7 +587,7 @@ namespace System.Windows.Forms.PropertyGridInternal
                        //Region clip = new Region();\r
                        //if (property_grid.SelectedGridItem != null)\r
                        //      clip.Union(new Rectangle(0,property_grid.SelectedGridItem.Top, ClientRectangle.Width, ROW_HEIGHT));\r
-                               //      clip.Union(new Rectangle(0,property_grid.SelectedGridItem.Top, ClientRectangle.Width, ROW_HEIGHT));\r
+                       //      clip.Union(new Rectangle(0,property_grid.SelectedGridItem.Top, ClientRectangle.Width, ROW_HEIGHT));\r
 \r
                        if (e.NewSelection.PropertyDescriptor != null)\r
                        {\r
@@ -655,8 +687,7 @@ namespace System.Windows.Forms.PropertyGridInternal
                        {\r
                                get\r
                                {\r
-                                       // TODO:  Add SystemComp.Instance getter implementation\r
-                                       return null;\r
+                                       return property_grid.SelectedGridItem.Value;\r
                                }\r
                        }\r
 \r
@@ -664,8 +695,7 @@ namespace System.Windows.Forms.PropertyGridInternal
                        {\r
                                get\r
                                {\r
-                                       // TODO:  Add SystemComp.PropertyDescriptor getter implementation\r
-                                       return null;\r
+                                       return property_grid.SelectedGridItem.PropertyDescriptor;\r
                                }\r
                        }\r
 \r
@@ -695,8 +725,8 @@ namespace System.Windows.Forms.PropertyGridInternal
                                get \r
                                {
                                        CreateParams cp = base.CreateParams;                            
-                                               cp.Style = unchecked ((int)(WindowStyles.WS_POPUP | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN));
-                                               cp.ExStyle |= (int)(WindowStyles.WS_EX_TOOLWINDOW | WindowStyles.WS_EX_TOPMOST);                                
+                                       cp.Style = unchecked ((int)(WindowStyles.WS_POPUP | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN));
+                                       cp.ExStyle |= (int)(WindowStyles.WS_EX_TOOLWINDOW | WindowStyles.WS_EX_TOPMOST);                                
                                        return cp;
                                }
                        }