* ImageList.cs: When the image stream is set pull all the images
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ImageList.cs
index 150cfb0d1fa4db813374b191fe6e806f95bb8af0..b1191f9dac0fed2c2e3d86bd657bdb7c49e12282 100644 (file)
@@ -17,7 +17,7 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
 //
 // Authors:
 //     Peter Bartok    pbartok@novell.com
@@ -32,6 +32,10 @@ using System.Drawing;
 using System.Drawing.Imaging;
 
 namespace System.Windows.Forms {
+       [DefaultProperty("Images")]
+       [Designer("System.Windows.Forms.Design.ImageListDesigner, " + Consts.AssemblySystem_Design)]
+       [ToolboxItemFilter("System.Windows.Forms", ToolboxItemFilterType.Allow)]
+       [TypeConverter("System.Windows.Forms.ImageListConverter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
        public sealed class ImageList : System.ComponentModel.Component {
                #region Local Variables
                private ColorDepth              color_depth;
@@ -43,6 +47,7 @@ namespace System.Windows.Forms {
                #endregion      // Local Variables
 
                #region Sub-classes
+               [Editor("System.Windows.Forms.Design.ImageCollectionEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
                public sealed class ImageCollection : IList, ICollection, IEnumerable {
                        #region ImageCollection Local Variables
                        private ImageList       owner;
@@ -57,6 +62,7 @@ namespace System.Windows.Forms {
                        #endregion      // ImageCollection Private Constructor
 
                        #region ImageCollection Public Instance Properties
+                       [Browsable(false)]
                        public int Count {
                                get {
                                        return list.Count;
@@ -75,6 +81,8 @@ namespace System.Windows.Forms {
                                }
                        }
 
+                       [Browsable(false)]
+                       [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                        public Image this[int index] {
                                get {
                                        if (index<0 || index>=list.Count) {
@@ -112,8 +120,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
@@ -124,7 +132,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);
@@ -344,11 +352,15 @@ namespace System.Windows.Forms {
 
                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
 
                #region Public Instance Properties
+               [DefaultValue(ColorDepth.Depth8Bit)]
                public ColorDepth ColorDepth {
                        get {
                                return this.color_depth;
@@ -360,6 +372,9 @@ 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);
@@ -368,18 +383,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 bool HandleCreated {
                        get {
                                return false;
                        }
                }
 
+               [DefaultValue(null)]
+               [MergableProperty(false)]
+               [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public ImageCollection Images {
                        get {
                                return this.image_collection;
                        }
                }
 
+               [Localizable(true)]
                public Size ImageSize {
                        get {
                                return this.size;
@@ -393,6 +415,9 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable(false)]
+               [DefaultValue(null)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                public ImageListStreamer ImageStream {
                        get {
                                return image_stream;
@@ -400,6 +425,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);
                        }
                }
 
@@ -448,6 +482,8 @@ namespace System.Windows.Forms {
                #endregion      // Protected Instance Methods
 
                #region Events
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                public event EventHandler RecreateHandle;
                #endregion      // Events
        }