2004-04-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / ImageList.cs
index aea07f34e656526d5c621f85325cdbecf7341d29..a1e17c940e73b8a932ea5a3568a72f39e8ee80ac 100644 (file)
-//\r
-// System.Windows.Forms.ImageList.cs\r
-//\r
-// Author:\r
-//   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)\r
-//     Dennis Hayes (dennish@raytek.com)\r
-//\r
-// (C) 2002 Ximian, Inc\r
-//\r
-using System.ComponentModel;\r
-using System.Drawing;\r
-using System.Collections;\r
-namespace System.Windows.Forms {\r
-\r
-       // <summary>\r
-       //\r
-       // </summary>\r
-    public sealed class ImageList : Component {\r
-               internal ColorDepth colorDepth;\r
-               //\r
-               //  --- Constructor\r
-               //\r
-\r
-               [MonoTODO]\r
-               public ImageList()\r
-               {\r
-                       colorDepth = ColorDepth.Depth8Bit;\r
-               }\r
-\r
-               [MonoTODO]\r
-               public ImageList(IContainer cont) : this()\r
-               {\r
-                       \r
-               }\r
-\r
-               //\r
-               //  --- Public Properties\r
-               //\r
-\r
-               [MonoTODO]\r
-               public ColorDepth ColorDepth {\r
-                       get {\r
-                               return colorDepth;\r
-                       }\r
-                       set {\r
-                               colorDepth = value;\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public IntPtr Handle {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public bool HandleCreated {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public ImageList.ImageCollection Images {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               internal Size imageSize; //FIXME: just to get it to run\r
-               [MonoTODO]\r
-               public Size ImageSize {\r
-                       get {\r
-                               return imageSize;\r
-                       }\r
-                       set {\r
-                               imageSize = value;\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public ImageListStreamer ImageStream {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-                       set {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               internal Color transparentColor; //FIXME: just to get it to run\r
-               [MonoTODO]\r
-               public Color TransparentColor {\r
-                       get {\r
-                               return transparentColor;\r
-                       }\r
-                       set {\r
-                               transparentColor = value;\r
-                       }\r
-               }\r
-\r
-               //\r
-               //  --- Public Methods\r
-               //\r
-\r
-               [MonoTODO]\r
-               public void Draw(Graphics g, Point pt, int n)\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public void Draw(Graphics g, int n1, int n2, int n3)\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public override string ToString()\r
-               {\r
-                       //FIXME:\r
-                       return base.ToString();\r
-               }\r
-\r
-               //\r
-               //  --- Public Events\r
-               //\r
-               public event EventHandler RecreateHandle;\r
-\r
-               //\r
-               // System.Windows.Forms.ImageList.ImageCollection.cs\r
-               //\r
-               // Author:\r
-               //   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)\r
-               //\r
-               //// (C) 2002 Ximian, Inc\r
-               ////\r
-               // <summary>\r
-               //\r
-               // </summary>\r
-\r
-               public sealed class ImageCollection : IList, ICollection, IEnumerable {\r
-\r
-\r
-               //\r
-               //  --- Public Properties\r
-               //\r
-\r
-               [MonoTODO]\r
-               public int Count {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public bool Empty {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public bool IsReadOnly {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               [MonoTODO]\r
-               public Image this[int index] {\r
-                       get {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-                       set {\r
-                               throw new NotImplementedException ();\r
-                       }\r
-               }\r
-\r
-               //\r
-               //  --- Public Methods\r
-               //\r
-\r
-               [MonoTODO]\r
-               public void Add(Icon icon)\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public void Add(Image img)\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public int Add(Image img, Color col)\r
-               {\r
-                       throw new NotImplementedException ();                   \r
-               }\r
-\r
-               [MonoTODO]\r
-               public int AddStrip(Image value)\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-               [MonoTODO]\r
-               public void Clear()\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public bool Contains(Image image)\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-               [MonoTODO]\r
-               public IEnumerator GetEnumerator()\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-               [MonoTODO]\r
-               public int IndexOf(Image image)\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-               [MonoTODO]\r
-               public void Remove(Image image)\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public void RemoveAt(int index)\r
-               {\r
-                       //FIXME:\r
-               }\r
-\r
-               [MonoTODO]\r
-               public override string ToString()\r
-               {\r
-                       //FIXME:\r
-                       return base.ToString();\r
-               }\r
-                       /// <summary>\r
-                       /// IList Interface implmentation.\r
-                       /// </summary>\r
-                       bool IList.IsReadOnly{\r
-                               get{\r
-                                       // We allow addition, removeal, and editing of items after creation of the list.\r
-                                       return false;\r
-                               }\r
-                       }\r
-                       bool IList.IsFixedSize{\r
-                               get{\r
-                                       // We allow addition and removeal of items after creation of the list.\r
-                                       return false;\r
-                               }\r
-                       }\r
-\r
-                       //[MonoTODO]\r
-                       object IList.this[int index]{\r
-                               get{\r
-                                       throw new NotImplementedException ();\r
-                               }\r
-                               set{\r
-                                       //FIXME:\r
-                               }\r
-                       }\r
-               \r
-                       [MonoTODO]\r
-                       void IList.Clear(){\r
-                               //FIXME:\r
-                       }\r
-               \r
-                       [MonoTODO]\r
-                       int IList.Add( object value){\r
-                               throw new NotImplementedException ();\r
-                       }\r
-\r
-                       [MonoTODO]\r
-                       bool IList.Contains( object value){\r
-                               throw new NotImplementedException ();\r
-                       }\r
-\r
-                       [MonoTODO]\r
-                       int IList.IndexOf( object value){\r
-                               throw new NotImplementedException ();\r
-                       }\r
-\r
-                       [MonoTODO]\r
-                       void IList.Insert(int index, object value){\r
-                               //FIXME:\r
-                       }\r
-\r
-                       [MonoTODO]\r
-                       void IList.Remove( object value){\r
-                               //FIXME:\r
-                       }\r
-\r
-                       [MonoTODO]\r
-                       void IList.RemoveAt( int index){\r
-                               //FIXME:\r
-                       }\r
-                       // End of IList interface\r
-                       /// <summary>\r
-                       /// ICollection Interface implmentation.\r
-                       /// </summary>\r
-                       int ICollection.Count{\r
-                               get{\r
-                                       throw new NotImplementedException ();\r
-                               }\r
-                       }\r
-                       bool ICollection.IsSynchronized{\r
-                               get{\r
-                                       throw new NotImplementedException ();\r
-                               }\r
-                       }\r
-                       object ICollection.SyncRoot{\r
-                               get{\r
-                                       throw new NotImplementedException ();\r
-                               }\r
-                       }\r
-                       void ICollection.CopyTo(Array array, int index){\r
-                               throw new NotImplementedException ();\r
-                       }\r
-                       // End Of ICollection\r
-\r
-               }// End of Subclass\r
-\r
-        }//End of class\r
-}\r
+//
+// System.Windows.Forms.ImageList.cs
+//
+// Author:
+//   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
+//     Dennis Hayes (dennish@raytek.com)
+//   Aleksey Ryabchuk (ryabchuk@yahoo.com)
+//
+// (C) 2002/3 Ximian, Inc
+//
+using System.ComponentModel;
+using System.Drawing;
+using System.Collections;
+using System.Runtime.Serialization;
+
+namespace System.Windows.Forms {
+
+       // <summary>
+       //
+       // </summary>
+    public sealed class ImageList : Component {
+               ColorDepth colorDepth;
+               Size       size;
+               Color      transparentColor;
+               IntPtr     handle;
+               ImageCollection images;
+
+               ImageListStreamer imageListStreamer;
+
+               [MonoTODO]
+               public ImageList() {
+                       colorDepth = ColorDepth.Depth4Bit;
+                       size = new Size ( 16, 16 );
+                       transparentColor = Color.Transparent;
+               }
+
+               [MonoTODO]
+               public ImageList(IContainer cont) : this() {
+                       cont.Add ( this );
+               }
+
+
+               [MonoTODO]
+               public ColorDepth ColorDepth {
+                       get {   return colorDepth; }
+                       set {
+                               if ( !Enum.IsDefined ( typeof( ColorDepth ), value ) )
+                                       throw new InvalidEnumArgumentException( "ColorDepth",
+                                               (int)value,
+                                               typeof( ColorDepth ) );
+
+                               if ( colorDepth != value ) {
+                                       colorDepth = value;
+                                       if ( HandleCreated )
+                                               recreateHandle ( );
+                               }
+                       }
+               }
+
+               [MonoTODO]
+               protected override void Dispose(bool disposing){
+                       base.Dispose(disposing);
+               }
+
+               [MonoTODO]
+               public IntPtr Handle {
+                       get {
+                               if ( !HandleCreated )
+                                       createHandle ( );
+                               return handle;
+                       }
+               }
+
+               [MonoTODO]
+               public bool HandleCreated {
+                       get {   return handle != IntPtr.Zero;   }
+               }
+
+               [MonoTODO]
+               public ImageList.ImageCollection Images {
+                       get {
+                               if ( images == null )
+                                       images = new ImageCollection ( this );
+                               return images;
+                       }
+               }
+
+               [MonoTODO]
+               public Size ImageSize {
+                       get {   return size;  }
+                       set {
+                               if ( value.IsEmpty || value.Width  <= 0 || value.Height <= 0 || 
+                                       value.Width  > 256 || value.Height > 256 )
+                                       throw new ArgumentException( ); // FIXME: message
+
+                               if ( size != value ) {
+                                       size = value;
+                                       if ( HandleCreated )
+                                               recreateHandle ( );
+                                       
+                               }
+                       }
+               }
+
+               [MonoTODO]
+               public ImageListStreamer ImageStream {
+                       get {
+                               return imageListStreamer;
+                       }
+                       set {
+                               imageListStreamer = value;
+                               destroyHandle ( );
+                               handle = imageListStreamer.Handle;
+                       }
+               }
+
+               [MonoTODO]
+               public Color TransparentColor {
+                       get {   return transparentColor; }
+                       set {   transparentColor = value;}
+               }
+
+               //
+               //  --- Public Methods
+               //
+
+               [MonoTODO]
+               public void Draw(Graphics g, Point pt, int index)
+               {
+                       //FIXME:
+               }
+
+               [MonoTODO]
+               public void Draw(Graphics g, int x, int y, int index)
+               {
+                       //FIXME:
+               }
+
+               [MonoTODO]
+               public void Draw(Graphics g, int x, int y, int width, int height, int index)
+               {
+                       //FIXME:
+               }
+
+               [MonoTODO]
+               public override string ToString()
+               {
+                       //FIXME:
+                       return base.ToString();
+               }
+
+               //
+               //  --- Public Events
+               //
+               public event EventHandler RecreateHandle;
+
+               private void createHandle ( )
+               {
+                       ImageListStreamer.initCommonControlsLibrary( );
+               }
+
+               private void recreateHandle ( ) {
+               }
+
+               private void destroyHandle ( )
+               {
+                       if ( HandleCreated )
+                               Win32.ImageList_Destroy ( handle );
+               }
+
+               //
+               // System.Windows.Forms.ImageList.ImageCollection.cs
+               //
+               // Author:
+               //   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
+               //   Aleksey Ryabchuk (ryabchuk@yahoo.com)
+               //// (C) 2002 Ximian, Inc
+               ////
+               // <summary>
+               //
+               // </summary>
+
+               public sealed class ImageCollection : IList, ICollection, IEnumerable {
+                       private ArrayList list;
+                       private ImageList owner;
+
+
+               public ImageCollection( ImageList owner )  {
+                       list = new ArrayList();
+                       this.owner = owner;
+               }
+
+               [MonoTODO]
+               public int Count {
+                       get { return list.Count; }
+               }
+
+               [MonoTODO]
+               public bool Empty {
+                       get { return list.Count == 0; }
+               }
+
+               [MonoTODO]
+               public bool IsReadOnly {
+                       get { return list.IsReadOnly; }
+               }
+
+               [MonoTODO]
+               public Image this[int index] {
+                       get {   return ( Image ) list[ index ]; }
+                       set {   list[ index ] = value;  }
+               }
+
+               [MonoTODO]
+               public void Add(Icon icon) {
+                       if ( icon == null )
+                               throw new ArgumentNullException("value");
+                       
+                       //list.Add( Bitmap.FromHicon ( icon.Handle ) );
+               }
+
+               [MonoTODO]
+               public void Add(Image img) {
+                       if ( img == null )
+                               throw new ArgumentNullException("value");
+
+                       list.Add( img );
+               }
+
+               [MonoTODO]
+               public int Add(Image img, Color col) {
+                       if ( img == null )
+                               throw new ArgumentNullException("value");
+
+                       return list.Add( img );
+               }
+
+               [MonoTODO]
+               public int AddStrip( Image value ) {
+                       return -1;
+               }
+
+               [MonoTODO]
+               public void Clear() {
+                       list.Clear ( );
+               }
+
+               [MonoTODO]
+               public bool Contains(Image image) {
+                       return list.Contains( image );
+               }
+
+               [MonoTODO]
+               public IEnumerator GetEnumerator() {
+                       return list.GetEnumerator();
+               }
+
+               [MonoTODO]
+               public int IndexOf(Image image) {
+                       return list.IndexOf( image );
+               }
+
+               [MonoTODO]
+               public void Remove(Image image) {
+                       list.Remove( image );
+               }
+
+               [MonoTODO]
+               public void RemoveAt(int index) {
+                       if (index < 0 || index > Count )
+                               throw new ArgumentOutOfRangeException( "index" );
+
+                       list.RemoveAt( index );
+               }
+
+               [MonoTODO]
+               public override string ToString()
+               {
+                       //FIXME:
+                       return base.ToString();
+               }
+                       /// <summary>
+                       /// IList Interface implmentation.
+                       /// </summary>
+                       bool IList.IsReadOnly{
+                               get{    return list.IsReadOnly; }
+                       }
+                       bool IList.IsFixedSize{
+                               get{    return list.IsFixedSize; }
+                       }
+
+                       object IList.this[int index]{
+                               get { return this[index]; }
+                               set { this[index]= (Image) value; }
+                       }
+               
+                       [MonoTODO]
+                       void IList.Clear(){
+                               Clear ( );
+                       }
+               
+                       [MonoTODO]
+                       int IList.Add( object value ){
+                               if (!(value is Image))
+                                       throw new ArgumentException();//FIXME: message
+
+                               Add( (Image) value );
+                               return Count;
+                       }
+
+                       [MonoTODO]
+                       bool IList.Contains( object value ){
+                               if (!(value is Image))
+                                       return false;
+                               return Contains( (Image) value );
+                       }
+
+                       [MonoTODO]
+                       int IList.IndexOf( object value ){
+                               if ( !( value is Image))
+                                       return -1;
+                               return IndexOf( (Image) value );
+                       }
+
+                       [MonoTODO]
+                       void IList.Insert( int index, object value ){
+                               if ( !( value is Image ) )
+                                       throw new ArgumentException();//FIXME: message
+                               
+                               list.Insert ( index, value );
+                       }
+
+                       [MonoTODO]
+                       void IList.Remove( object value ){
+                               if ( !(value is Image) )
+                                       throw new ArgumentException(); //FIXME: message
+
+                               Remove( (Image) value);
+                       }
+
+                       [MonoTODO]
+                       void IList.RemoveAt( int index ){
+                               RemoveAt ( index );
+                       }
+                       // End of IList interface
+
+                       /// <summary>
+                       /// ICollection Interface implmentation.
+                       /// </summary>
+                       int ICollection.Count{
+                               get{    return Count;  }
+                       }
+                       bool ICollection.IsSynchronized{
+                               get{    return list.IsSynchronized; }
+                       }
+                       object ICollection.SyncRoot{
+                               get{    return list.SyncRoot;   }
+                       }
+                       void ICollection.CopyTo(Array array, int index){
+                               list.CopyTo ( array, index );
+                       }
+                       // End Of ICollection
+
+               }// End of Subclass
+
+        }//End of class
+}