1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/External/Aga.Controls/Tree/NodeControls/ExpandingIcon.cs Sun May 27 15:16:19 2012 +0000
1.3 @@ -0,0 +1,83 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Text;
1.7 +using System.Drawing;
1.8 +using System.Threading;
1.9 +using System.Windows.Forms;
1.10 +
1.11 +namespace Aga.Controls.Tree.NodeControls
1.12 +{
1.13 + /// <summary>
1.14 + /// Displays an animated icon for those nodes, who are in expanding state.
1.15 + /// Parent TreeView must have AsyncExpanding property set to true.
1.16 + /// </summary>
1.17 + public class ExpandingIcon: NodeControl
1.18 + {
1.19 + private static GifDecoder _gif = ResourceHelper.LoadingIcon;
1.20 + private static int _index = 0;
1.21 + private static volatile Thread _animatingThread;
1.22 + private static object _lock = new object();
1.23 +
1.24 + public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
1.25 + {
1.26 + return ResourceHelper.LoadingIcon.FrameSize;
1.27 + }
1.28 +
1.29 + protected override void OnIsVisibleValueNeeded(NodeControlValueEventArgs args)
1.30 + {
1.31 + args.Value = args.Node.IsExpandingNow;
1.32 + base.OnIsVisibleValueNeeded(args);
1.33 + }
1.34 +
1.35 + public override void Draw(TreeNodeAdv node, DrawContext context)
1.36 + {
1.37 + Rectangle rect = GetBounds(node, context);
1.38 + Image img = _gif.GetFrame(_index).Image;
1.39 + context.Graphics.DrawImage(img, rect.Location);
1.40 + }
1.41 +
1.42 + public static void Start()
1.43 + {
1.44 + lock (_lock)
1.45 + {
1.46 + if (_animatingThread == null)
1.47 + {
1.48 + _index = 0;
1.49 + _animatingThread = new Thread(new ThreadStart(IterateIcons));
1.50 + _animatingThread.IsBackground = true;
1.51 + _animatingThread.Priority = ThreadPriority.Lowest;
1.52 + _animatingThread.Start();
1.53 + }
1.54 + }
1.55 + }
1.56 +
1.57 + public static void Stop()
1.58 + {
1.59 + lock (_lock)
1.60 + {
1.61 + _index = 0;
1.62 + _animatingThread = null;
1.63 + }
1.64 + }
1.65 +
1.66 + private static void IterateIcons()
1.67 + {
1.68 + while (_animatingThread != null)
1.69 + {
1.70 + if (_index < _gif.FrameCount - 1)
1.71 + _index++;
1.72 + else
1.73 + _index = 0;
1.74 +
1.75 + if (IconChanged != null)
1.76 + IconChanged(null, EventArgs.Empty);
1.77 +
1.78 + int delay = _gif.GetFrame(_index).Delay;
1.79 + Thread.Sleep(delay);
1.80 + }
1.81 + System.Diagnostics.Debug.WriteLine("IterateIcons Stopped");
1.82 + }
1.83 +
1.84 + public static event EventHandler IconChanged;
1.85 + }
1.86 +}