2 // System.Windows.Forms.ImageList.cs
5 // stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
6 // Dennis Hayes (dennish@raytek.com)
7 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
9 // (C) 2002/3 Ximian, Inc
11 using System.ComponentModel;
13 using System.Collections;
14 using System.Runtime.Serialization;
16 namespace System.Windows.Forms {
21 public sealed class ImageList : Component {
22 ColorDepth colorDepth;
24 Color transparentColor;
26 ImageCollection images;
28 ImageListStreamer imageListStreamer;
32 colorDepth = ColorDepth.Depth4Bit;
33 size = new Size ( 16, 16 );
34 transparentColor = Color.Transparent;
38 public ImageList(IContainer cont) : this() {
44 public ColorDepth ColorDepth {
45 get { return colorDepth; }
47 if ( !Enum.IsDefined ( typeof( ColorDepth ), value ) )
48 throw new InvalidEnumArgumentException( "ColorDepth",
50 typeof( ColorDepth ) );
52 if ( colorDepth != value ) {
61 protected override void Dispose(bool disposing){
62 base.Dispose(disposing);
66 public IntPtr Handle {
75 public bool HandleCreated {
76 get { return handle != IntPtr.Zero; }
80 public ImageList.ImageCollection Images {
83 images = new ImageCollection ( this );
89 public Size ImageSize {
92 if ( value.IsEmpty || value.Width <= 0 || value.Height <= 0 ||
93 value.Width > 256 || value.Height > 256 )
94 throw new ArgumentException( ); // FIXME: message
96 if ( size != value ) {
106 public ImageListStreamer ImageStream {
108 return imageListStreamer;
111 imageListStreamer = value;
113 handle = imageListStreamer.Handle;
118 public Color TransparentColor {
119 get { return transparentColor; }
120 set { transparentColor = value;}
124 // --- Public Methods
128 public void Draw(Graphics g, Point pt, int index)
134 public void Draw(Graphics g, int x, int y, int index)
140 public void Draw(Graphics g, int x, int y, int width, int height, int index)
146 public override string ToString()
149 return base.ToString();
155 public event EventHandler RecreateHandle;
157 private void createHandle ( )
159 ImageListStreamer.initCommonControlsLibrary( );
162 private void recreateHandle ( ) {
165 private void destroyHandle ( )
168 Win32.ImageList_Destroy ( handle );
172 // System.Windows.Forms.ImageList.ImageCollection.cs
175 // stubbed out by Daniel Carrera (dcarrera@math.toronto.edu)
176 // Aleksey Ryabchuk (ryabchuk@yahoo.com)
177 //// (C) 2002 Ximian, Inc
183 public sealed class ImageCollection : IList, ICollection, IEnumerable {
184 private ArrayList list;
185 private ImageList owner;
188 public ImageCollection( ImageList owner ) {
189 list = new ArrayList();
195 get { return list.Count; }
200 get { return list.Count == 0; }
204 public bool IsReadOnly {
205 get { return list.IsReadOnly; }
209 public Image this[int index] {
210 get { return ( Image ) list[ index ]; }
211 set { list[ index ] = value; }
215 public void Add(Icon icon) {
217 throw new ArgumentNullException("value");
219 //list.Add( Bitmap.FromHicon ( icon.Handle ) );
223 public void Add(Image img) {
225 throw new ArgumentNullException("value");
231 public int Add(Image img, Color col) {
233 throw new ArgumentNullException("value");
235 return list.Add( img );
239 public int AddStrip( Image value ) {
244 public void Clear() {
249 public bool Contains(Image image) {
250 return list.Contains( image );
254 public IEnumerator GetEnumerator() {
255 return list.GetEnumerator();
259 public int IndexOf(Image image) {
260 return list.IndexOf( image );
264 public void Remove(Image image) {
265 list.Remove( image );
269 public void RemoveAt(int index) {
270 if (index < 0 || index > Count )
271 throw new ArgumentOutOfRangeException( "index" );
273 list.RemoveAt( index );
277 public override string ToString()
280 return base.ToString();
283 /// IList Interface implmentation.
285 bool IList.IsReadOnly{
286 get{ return list.IsReadOnly; }
288 bool IList.IsFixedSize{
289 get{ return list.IsFixedSize; }
292 object IList.this[int index]{
293 get { return this[index]; }
294 set { this[index]= (Image) value; }
303 int IList.Add( object value ){
304 if (!(value is Image))
305 throw new ArgumentException();//FIXME: message
307 Add( (Image) value );
312 bool IList.Contains( object value ){
313 if (!(value is Image))
315 return Contains( (Image) value );
319 int IList.IndexOf( object value ){
320 if ( !( value is Image))
322 return IndexOf( (Image) value );
326 void IList.Insert( int index, object value ){
327 if ( !( value is Image ) )
328 throw new ArgumentException();//FIXME: message
330 list.Insert ( index, value );
334 void IList.Remove( object value ){
335 if ( !(value is Image) )
336 throw new ArgumentException(); //FIXME: message
338 Remove( (Image) value);
342 void IList.RemoveAt( int index ){
345 // End of IList interface
348 /// ICollection Interface implmentation.
350 int ICollection.Count{
353 bool ICollection.IsSynchronized{
354 get{ return list.IsSynchronized; }
356 object ICollection.SyncRoot{
357 get{ return list.SyncRoot; }
359 void ICollection.CopyTo(Array array, int index){
360 list.CopyTo ( array, index );
362 // End Of ICollection