Author: jpobst
Date: 2007-09-07 10:22:41 -0400 (Fri, 07 Sep 2007)
New Revision: 85478

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs
Log:
2007-09-07  Jonathan Pobst  <[EMAIL PROTECTED]>

        * ToolStripItem.cs: Add support for animated images.
        [Fixes bug #82726]

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-09-07 14:17:58 UTC (rev 85477)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2007-09-07 14:22:41 UTC (rev 85478)
@@ -1,5 +1,10 @@
 2007-09-07  Jonathan Pobst  <[EMAIL PROTECTED]>
 
+       * ToolStripItem.cs: Add support for animated images.
+       [Fixes bug #82726]
+
+2007-09-07  Jonathan Pobst  <[EMAIL PROTECTED]>
+
        * ToolStrip.cs: Make sure we aren't drawing anything that isn't 
        visible.  [Fixes bug #82727]
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs 
2007-09-07 14:17:58 UTC (rev 85477)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ToolStripItem.cs 
2007-09-07 14:22:41 UTC (rev 85478)
@@ -90,6 +90,7 @@
                private string tool_tip_text;
                private bool visible;
 
+               private EventHandler frame_handler;     // For animating images
                private ToolStrip parent;
                private Size text_size;
                #endregion
@@ -454,11 +455,15 @@
                        }
                        set {
                                if (this.image != value) {
+                                       StopAnimation ();
+                                       
                                        this.image = value; 
                                        this.image_index = -1;
                                        this.image_key = string.Empty;
                                        this.CalculateAutoSize (); 
                                        this.Invalidate ();
+                                       
+                                       BeginAnimation ();
                                }
                        }
                }
@@ -904,7 +909,12 @@
                {
                        if (!is_disposed && disposing)
                                is_disposed = true;
-                               
+
+                       if (image != null) {
+                               StopAnimation ();
+                               image = null;
+                       }
+                       
                        base.Dispose (disposing);
                }
                
@@ -1228,6 +1238,11 @@
                        this.visible = visible;
                        this.OnVisibleChanged (EventArgs.Empty);
                        this.Invalidate ();
+                       
+                       if (this.visible)
+                               BeginAnimation ();
+                       else
+                               StopAnimation ();
                }
                #endregion
 
@@ -1450,7 +1465,6 @@
 
                        if (final_size != this.Size) {
                                this.bounds.Width = final_size.Width;
-                               this.Invalidate ();
                                if (this.parent != null)
                                        this.parent.PerformLayout ();
                        }
@@ -1728,6 +1742,47 @@
                        this.placement = placement;
                }
 
+               private void BeginAnimation ()
+               {
+                       if (image != null && ImageAnimator.CanAnimate (image)) {
+                               frame_handler = new EventHandler 
(OnAnimateImage);
+                               ImageAnimator.Animate (image, frame_handler);
+                       }
+               }
+
+               private void OnAnimateImage (object sender, EventArgs e)
+               {
+                       // This is called from a worker thread,BeginInvoke is 
used
+                       // so the control is updated from the correct thread
+
+                       // Check if we have a handle again, since it may have 
gotten
+                       // destroyed since the last time we checked.
+                       if (Parent == null || !Parent.IsHandleCreated)
+                               return;
+
+                       Parent.BeginInvoke (new EventHandler 
(UpdateAnimatedImage), new object[] { this, e });
+               }
+
+               private void StopAnimation ()
+               {
+                       if (frame_handler == null)
+                               return;
+                               
+                       ImageAnimator.StopAnimate (image, frame_handler);
+                       frame_handler = null;
+               }
+
+               private void UpdateAnimatedImage (object sender, EventArgs e)
+               {
+                       // Check if we have a handle again, since it may have 
gotten
+                       // destroyed since the last time we checked.
+                       if (Parent == null || !Parent.IsHandleCreated)
+                               return;
+
+                       ImageAnimator.UpdateFrames (image);
+                       Invalidate ();
+               }
+
                internal bool ShowMargin {
                        get {
                                if (!this.IsOnDropDown)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to