2005-09-08 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ImageList.cs
index fa7a4f0beb3e8ae3a424944805e8cb8119ee8c9e..791090bba161a59d86f9adf51f9f846982733150 100644 (file)
 //     Peter Bartok    pbartok@novell.com
 //
 
+// If we ever need to support the Handle property, we should create a static ArrayList,
+// and store the ImageList object in it, and return the index as handle
+// That way, once we try to support P/Invokes, we can make the handle back to the object
+
 
 // COMPLETE
 
@@ -33,9 +37,9 @@ using System.Drawing.Imaging;
 
 namespace System.Windows.Forms {
        [DefaultProperty("Images")]
-       [Designer("System.Windows.Forms.Design.ImageListDesigner, " + Consts.AssemblySystem_Design)]
+       [Designer("System.Windows.Forms.Design.ImageListDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
        [ToolboxItemFilter("System.Windows.Forms", ToolboxItemFilterType.Allow)]
-       [TypeConverter("System.Windows.Forms.ImageListConverter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+       [TypeConverter("System.Windows.Forms.ImageListConverter, " + Consts.AssemblySystem_Windows_Forms)]
        public sealed class ImageList : System.ComponentModel.Component {
                #region Local Variables
                private ColorDepth              color_depth;
@@ -44,6 +48,7 @@ namespace System.Windows.Forms {
                private Color                   transparency_color;
                private Delegate                handler;
                private ImageListStreamer       image_stream;
+               private IntPtr                  handle; 
                #endregion      // Local Variables
 
                #region Sub-classes
@@ -120,8 +125,8 @@ namespace System.Windows.Forms {
                                        case ColorDepth.Depth8Bit:      format=PixelFormat.Format8bppIndexed; break;
                                        case ColorDepth.Depth16Bit:     format=PixelFormat.Format16bppRgb555; break;
                                        case ColorDepth.Depth24Bit:     format=PixelFormat.Format24bppRgb; break;
-                                       case ColorDepth.Depth32Bit:     format=PixelFormat.Format32bppRgb; break;
-                                       default:                        format=PixelFormat.Format32bppRgb; break;
+                                       case ColorDepth.Depth32Bit:     format=PixelFormat.Format32bppArgb; break;
+                                       default:                        format=PixelFormat.Format32bppArgb; break;
                                }
 
                                // Check if we can add straight or if we have to resize
@@ -132,7 +137,7 @@ namespace System.Windows.Forms {
                                        reformatted_image = new Bitmap(width, height, format);
                                        g=Graphics.FromImage(reformatted_image);
 
-                                       g.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
+                                       g.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                                        g.Dispose();
 
                                        return list.Add(reformatted_image);
@@ -348,10 +353,14 @@ namespace System.Windows.Forms {
                        transparency_color = Color.Transparent;
                        size = new Size(16, 16);
                        image_collection = new ImageCollection(this);
+                       handle = IntPtr.Zero;
                }
 
                public ImageList(System.ComponentModel.IContainer container) : this ()
                {
+                       color_depth = ColorDepth.Depth8Bit;
+                       transparency_color = Color.Transparent;
+                       size = new Size(16, 16);
                        container.Add (this);
                }
                #endregion      // Public Constructors
@@ -368,23 +377,25 @@ namespace System.Windows.Forms {
                        }
                }
 
-               [MonoTODO("Determine if we support HBITMAP handles, this would involve XplatUI")]
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public IntPtr Handle {
                        get {
                                if (RecreateHandle!=null) RecreateHandle(this, EventArgs.Empty);
-                               return IntPtr.Zero;
+                               handle = new IntPtr(1);
+                               return handle;
                        }
                }
 
-               [MonoTODO("Determine if we support HBITMAP handles, this would involve XplatUI")]
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public bool HandleCreated {
                        get {
+                               if (handle != IntPtr.Zero) {
+                                       return true;
+                               }
                                return false;
                        }
                }
@@ -422,6 +433,15 @@ namespace System.Windows.Forms {
 
                        set {
                                image_stream = value;
+
+                               size = image_stream.ImageSize;
+                               color_depth = image_stream.ImageColorDepth;
+                               transparency_color = image_stream.BackColor;
+
+                               image_collection.Clear ();
+
+                               foreach (Image image in image_stream.Images)
+                                       image_collection.Add (image);
                        }
                }
 
@@ -455,8 +475,8 @@ namespace System.Windows.Forms {
                        g.DrawImage(i, x, y, width, height);
                }
 
-               public override string ToString() {\r
-                       return "ImageList Size "+this.size.Width.ToString()+"x"+this.size.Height.ToString()+", Depth "+this.color_depth.ToString()+", Transparency color "+this.transparency_color.ToString();\r
+               public override string ToString() {
+                       return base.ToString () + " Images.Count: " + Images.Count + ", ImageSize: " + ImageSize;\r
                }
                #endregion      // Public Instance Methods