2004-04-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / ImageList.cs
index fcff5878d84b4ccafb5d6da219f07b55bb0cc9b7..a1e17c940e73b8a932ea5a3568a72f39e8ee80ac 100644 (file)
 //
-// System.Windows.Forms.ImageList
+// 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 Ximian, Inc
+// (C) 2002/3 Ximian, Inc
 //
+using System.ComponentModel;
+using System.Drawing;
+using System.Collections;
+using System.Runtime.Serialization;
 
 namespace System.Windows.Forms {
 
        // <summary>
-       //      This is only a template.  Nothing is implemented yet.
        //
        // </summary>
+    public sealed class ImageList : Component {
+               ColorDepth colorDepth;
+               Size       size;
+               Color      transparentColor;
+               IntPtr     handle;
+               ImageCollection images;
 
-        //public sealed class ImageList : Component {
+               ImageListStreamer imageListStreamer;
 
-               //
-               //  --- Constructor
-               //
-               //[MonoTODO]
-               //public ImageList()
-               //{
-               //      throw new NotImplementedException ();
-               //}
-               //[MonoTODO]
-               //public ImageList(IContainer cont)
-               //{
-               //      throw new NotImplementedException ();
-               //}
+               [MonoTODO]
+               public ImageList() {
+                       colorDepth = ColorDepth.Depth4Bit;
+                       size = new Size ( 16, 16 );
+                       transparentColor = Color.Transparent;
+               }
 
-               //
-               //  --- Public Properties
-               //
-               //[MonoTODO]
-               //public ColorDepth ColorDepth {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
-               //[MonoTODO]
-               //public IntPtr Handle {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
-               //[MonoTODO]
-               //public bool HandleCreated {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
-               //[MonoTODO]
-               //public ImageList.ImageCollection Images {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
-               //[MonoTODO]
-               //public Size ImageSize {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //      set {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
-               //[MonoTODO]
-               //public ImageListStreamer ImageStream {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //      set {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
-               //[MonoTODO]
-               //public Color TransparentColor {
-               //      get {
-               //              throw new NotImplementedException ();
-               //      }
-               //      set {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
+               [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 Dispose()
-               //{
-               //      throw new NotImplementedException ();
-               //}
-               //[MonoTODO]
-               //public void Draw(Graphics g, Point pt, int n)
-               //{
-               //      throw new NotImplementedException ();
-               //}
-               //[MonoTODO]
-               //public void Draw(Graphics g, int n1, int n2, int n3)
-               //{
-               //      throw new NotImplementedException ();
-               //}
-               //[MonoTODO]
-               //public virtual bool Equals(object o);
-               //{
-               //      throw new NotImplementedException ();
-               //}
-               //[MonoTODO]
-               //public static bool Equals(object o1, object o2);
-               //{
-               //      throw new NotImplementedException ();
-               //}
-               //[MonoTODO]
-               //public override string ToString()
-               //{
-               //      throw new NotImplementedException ();
-               //}
+
+               [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
                //
-               //[MonoTODO]
-               //public event EventHandler RecreateHandle {
-               //      add {
-               //              throw new NotImplementedException ();
-               //      }
-               //      remove {
-               //              throw new NotImplementedException ();
-               //      }
-               //}
+               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
                //
-               //  --- Protected Methods
+               // Author:
+               //   stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
+               //   Aleksey Ryabchuk (ryabchuk@yahoo.com)
+               //// (C) 2002 Ximian, Inc
+               ////
+               // <summary>
                //
-               //[MonoTODO]
-               //protected virtual void Dispose(bool val)
-               //{
-               //      throw new NotImplementedException ();
-               //}
-       // }
+               // </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
 }