using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;

namespace Telerik.QuickStart.WinControls
{
	public partial class PreviewForm : ExamplesForm
	{
		ExamplesTreeNode exampleNode;

		public PreviewForm()
		{
			InitializeComponent();
			this.AutoSize = false;
			this.Load += new EventHandler(PreviewForm_Load);
		}

		void PreviewForm_Load(object sender, EventArgs e)
		{
			//this.radButton1.BringToFront();
			//this.radButton1.BackColor = Color.Transparent;
		}

		public delegate void AnimationFinishedCallback();

		private void AnimateFlyIn(RadControl targetControl, Point startLocation, AnimationFinishedCallback callBack)
		{
			Point endLocation = targetControl.Location;
			endLocation.Y = this.Height - targetControl.Height - 10;
			
			AnimatedPropertySetting setting = new AnimatedPropertySetting(
				RootRadElement.ControlBoundsProperty, //target property
				new Rectangle(startLocation, targetControl.Size),		//initial value
				new Rectangle(endLocation, targetControl.Size),			//end value
				60, //interval
				10 // number of repetitions
				);

			//setting.ResetValueAfterRemove = true;
			setting.ApplyEasingType = RadEasingType.OutBounce;
			setting.RemoveAfterApply = true;
			setting.SkipToEndValueOnReplace = false;
			setting.ApplyValue(targetControl.RootElement);
		
			setting.AnimationFinished += delegate
			{
				//perform actions when animation has finished...
				 targetControl.Location = new Point(targetControl.Location.X, this.Height - targetControl.Height - 10);

				if (callBack != null)
					callBack();
			};
		}

		public Image PreviewImage
		{
			get
			{
				return pictureBox1.Image;
			}
			set
			{
				pictureBox1.Image = value;
			}
		}

		public ExamplesTreeNode ExampleNode
		{
			get 
			{
				return exampleNode;
			}
			set
			{
				exampleNode = value;
			}
		}

		private void radButton1_Click(object sender, EventArgs e)
		{
			if (exampleNode != null)
			{
				Form form = exampleNode.Form as Form;

				if (form != null)
				{
					form.StartPosition = FormStartPosition.CenterScreen;
					form.Icon = this.FindForm().Icon;
					form.Show();
				}
			}
		}

	}
}