2006-12-31 Chris Toshok <toshok@ximian.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ImageList.cs
index a4dcd9e548c8a3a763903c88abe120330a2e3cff..5a6f4de4bba0174833b8d6bd7bbeb5b70a01cb9d 100644 (file)
 // and ColorDepth that are treated as bugs and MS.NET 2.0 behavior is
 // implemented.
 //
-// MS.NET 2.0 initializes TransparentColor to Color.Transparent in
-// constructors but ResetTransparentColor and ShouldSerializeTransparentColor
-// default to Color.LightGray that is treated as a bug.
-//
 // MS.NET 2.0 does not clear keys when handle is destroyed that is treated as
 // a bug.
 //
@@ -93,7 +89,6 @@ namespace System.Windows.Forms
 #if NET_2_0
                private object tag;
 #endif
-               private EventHandler recreateHandle;
                private readonly ImageCollection images;
                #endregion // Private Fields
 
@@ -971,49 +966,56 @@ namespace System.Windows.Forms
                #region Private Instance Methods
                private void OnRecreateHandle()
                {
-                       if (this.recreateHandle != null)
-                               this.recreateHandle(this, EventArgs.Empty);
+                       EventHandler eh = (EventHandler)(Events [RecreateHandleEvent]);
+                       if (eh != null)
+                               eh (this, EventArgs.Empty);
                }
 
-#if NET_2_0
-               // For use in Designers
-               private void ResetColorDepth()
-               {
-                       this.ColorDepth = DefaultColorDepth;
-               }
-
-               // For use in Designers
-               private void ResetImageSize()
-               {
-                       this.ImageSize = DefaultImageSize;
-               }
+               // MS's TypeDescriptor stuff apparently uses
+               // non-public ShouldSerialize* methods, because it
+               // picks up this behavior even though the methods
+               // aren't public.  we can't make them private, though,
+               // without adding compiler warnings.  so, make then
+               // internal instead.
 
-               // For use in Designers
-               private void ResetTransparentColor()
+               internal bool ShouldSerializeTransparentColor ()
                {
-                       this.TransparentColor = DefaultTransparentColor;
+                       return this.TransparentColor != Color.LightGray;
                }
 
-               // For use in Designers
-               private bool ShouldSerializeColorDepth()
+               internal bool ShouldSerializeColorDepth()
                {
                        // ColorDepth is serialized in ImageStream when non-empty.
                        // It is serialized even if it has its default value when empty.
                        return images.Empty;
-               }
+               }               
 
-               // For use in Designers
-               private bool ShouldSerializeImageSize()
+               internal bool ShouldSerializeImageSize()
                {
                        // ImageSize is serialized in ImageStream when non-empty.
                        // It is serialized even if it has its default value when empty.
+#if NET_2_0
                        return images.Empty;
+#else
+                       return this.ImageSize != DefaultImageSize;
+#endif
                }
 
-               // For use in Designers
-               private bool ShouldSerializeTransparentColor()
+
+               internal void ResetColorDepth ()
                {
-                       return this.TransparentColor != DefaultTransparentColor;
+                       this.ColorDepth = DefaultColorDepth;
+               }
+
+#if NET_2_0
+               internal void ResetImageSize ()
+               {
+                       this.ImageSize = DefaultImageSize;
+               }
+
+               internal void ResetTransparentColor ()
+               {
+                       this.TransparentColor = Color.LightGray;
                }
 #endif
                #endregion // Private Instance Methods
@@ -1143,16 +1145,13 @@ namespace System.Windows.Forms
                #endregion // Protected Instance Methods
 
                #region Events
+               static object RecreateHandleEvent = new object ();
+
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                public event EventHandler RecreateHandle {
-                       add {
-                               this.recreateHandle += value;
-                       }
-
-                       remove {
-                               this.recreateHandle -= value;
-                       }
+                       add { Events.AddHandler (RecreateHandleEvent, value); }
+                       remove { Events.RemoveHandler (RecreateHandleEvent, value); }
                }
                #endregion // Events
        }