* 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 2b275121d8fe5e1097b059df0aa0e401fc595a85..b1191f9dac0fed2c2e3d86bd657bdb7c49e12282 100644 (file)
 // 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
 //
-//
-// $Log: ImageList.cs,v $
-// Revision 1.7  2004/11/04 11:04:40  ravindra
-// Implemented the missing overload for Draw method.
-//
-// Revision 1.6  2004/08/21 01:50:52  ravindra
-// Changed draw method to use the arguments passed in to draw the image.
-//
-// Revision 1.5  2004/08/19 21:39:09  pbartok
-// - Added missing Draw() method
-// - Added missing RecreateHandle event
-//
-// Revision 1.4  2004/08/11 17:43:08  pbartok
-// - Removed disposing of the actual images when the list is disposed
-//
-// Revision 1.3  2004/08/11 13:43:13  pbartok
-// - Added missing creation of the collection list
-//
-// Revision 1.2  2004/08/09 23:12:13  pbartok
-// - Fixed several bugs Ravindra pointed out
-//
-// Revision 1.1  2004/07/15 20:05:28  pbartok
-// - Implemented ImageList and ImageList.ImageCollection classes
-// - Added ColorDepth enumeration
-// - Updated SWF VS.Net project
-//
-//
+
 
 // COMPLETE
 
@@ -58,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;
@@ -69,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;
@@ -83,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;
@@ -101,6 +81,8 @@ namespace System.Windows.Forms {
                                }
                        }
 
+                       [Browsable(false)]
+                       [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                        public Image this[int index] {
                                get {
                                        if (index<0 || index>=list.Count) {
@@ -138,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
@@ -150,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);
@@ -368,13 +350,17 @@ namespace System.Windows.Forms {
                        image_collection = new ImageCollection(this);
                }
 
-               [MonoTODO]
-               public ImageList(System.ComponentModel.IContainer container) {
-                       throw new NotImplementedException();
+               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;
@@ -386,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);
@@ -394,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;
@@ -419,6 +415,9 @@ namespace System.Windows.Forms {
                        }
                }
 
+               [Browsable(false)]
+               [DefaultValue(null)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                public ImageListStreamer ImageStream {
                        get {
                                return image_stream;
@@ -426,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);
                        }
                }
 
@@ -474,6 +482,8 @@ namespace System.Windows.Forms {
                #endregion      // Protected Instance Methods
 
                #region Events
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Advanced)]
                public event EventHandler RecreateHandle;
                #endregion      // Events
        }