2005-09-08 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ListViewItemConverter.cs
index ed4f68ac5668f23f6aad36f3df96785bf6f67cff..53975c93fa0dbb2d00b56879f9305b5a0c481015 100644 (file)
 //
 // Authors:
 //     Ravindra (rkumar@novell.com)
-//
-// $Revision: 1.1 $
-// $Modtime: $
-// $Log: ListViewItemConverter.cs,v $
-// Revision 1.1  2004/09/30 13:26:35  ravindra
-// Converter for ListViewItem.
-//
-//
-// NOTE COMPLETE
-//
+
+
+// COMPLETE
+
 
 using System;
+using System.Collections;
 using System.ComponentModel;
+using System.ComponentModel.Design.Serialization;
+using System.Drawing;
 using System.Globalization;
+using System.Reflection;
 
 namespace System.Windows.Forms
 {
@@ -45,10 +43,11 @@ namespace System.Windows.Forms
                #endregion      // Public Constructors
 
                #region Public Instance Methods
-               public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
-               {
-                       if (destinationType == typeof (string))
+               public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) {
+                       if (destinationType == typeof (string)) {
                                return true;
+                       }
+
                        return base.CanConvertTo (context, destinationType);
                }
 
@@ -56,10 +55,42 @@ namespace System.Windows.Forms
                                                  CultureInfo culture, object value,
                                                  Type destinationType)
                {
-                       if (destinationType == typeof (string))
+                       if (destinationType == typeof (string)) {
                                return value.ToString ();
-                       else
+                       } else {
                                return base.ConvertTo (context, culture, value, destinationType);
+                       }
+               }
+               #endregion      // Public Instance Methods
+       }
+
+       internal class ListViewSubItemConverter : ExpandableObjectConverter {
+               #region Public Instance Methods
+               public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType) {
+                       if (destinationType == typeof(InstanceDescriptor)) {
+                               return true;
+                       } else {
+                               return base.CanConvertTo(context, destinationType);
+                       }
+               }
+
+               public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
+                       if (destinationType == typeof(InstanceDescriptor) && value is ListViewItem.ListViewSubItem) {
+                               ConstructorInfo                 constructor_info;
+                               Type[]                          type;
+                               ListViewItem.ListViewSubItem    sub_item;
+
+                               sub_item = (ListViewItem.ListViewSubItem)value;
+                               type = new Type[] { typeof(ListViewItem), typeof(string), typeof(Color), typeof(Color), typeof(Font)};
+
+                               constructor_info = typeof(ListViewItem.ListViewSubItem).GetConstructor(type);
+                               if (constructor_info != null) {
+                                       object[] arguments = new object[] {sub_item.Text, sub_item.ForeColor, sub_item.BackColor, sub_item.Font};
+                                       return new InstanceDescriptor(constructor_info, (ICollection) arguments, true);
+                               }
+
+                       }
+                       return base.ConvertTo(context, culture, value, destinationType);
                }
                #endregion      // Public Instance Methods
        }