using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Sample07_ExternalInterface
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.Button ButtonOrder;
		internal System.Windows.Forms.Button ButtonAbout;
		internal System.Windows.Forms.Button ButtonCallActionScriptFunction;
		private f_in_box__lib.f_in_box__control f_in_box__control1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.ButtonOrder = new System.Windows.Forms.Button();
			this.ButtonAbout = new System.Windows.Forms.Button();
			this.ButtonCallActionScriptFunction = new System.Windows.Forms.Button();
			this.f_in_box__control1 = new f_in_box__lib.f_in_box__control();
			this.SuspendLayout();
			// 
			// ButtonOrder
			// 
			this.ButtonOrder.Location = new System.Drawing.Point(448, 411);
			this.ButtonOrder.Name = "ButtonOrder";
			this.ButtonOrder.Size = new System.Drawing.Size(176, 23);
			this.ButtonOrder.TabIndex = 10;
			this.ButtonOrder.Text = "Buy license";
			// 
			// ButtonAbout
			// 
			this.ButtonAbout.Location = new System.Drawing.Point(448, 379);
			this.ButtonAbout.Name = "ButtonAbout";
			this.ButtonAbout.Size = new System.Drawing.Size(176, 23);
			this.ButtonAbout.TabIndex = 9;
			this.ButtonAbout.Text = "More about F-IN-BOX";
			// 
			// ButtonCallActionScriptFunction
			// 
			this.ButtonCallActionScriptFunction.Location = new System.Drawing.Point(8, 379);
			this.ButtonCallActionScriptFunction.Name = "ButtonCallActionScriptFunction";
			this.ButtonCallActionScriptFunction.Size = new System.Drawing.Size(224, 56);
			this.ButtonCallActionScriptFunction.TabIndex = 8;
			this.ButtonCallActionScriptFunction.Text = "Call ActionScript function";
			this.ButtonCallActionScriptFunction.Click += new System.EventHandler(this.ButtonCallActionScriptFunction_Click);
			// 
			// f_in_box__control1
			// 
			this.f_in_box__control1.Context = null;
			this.f_in_box__control1.FlashProperty_AlignMode = 0;
			this.f_in_box__control1.FlashProperty_AllowScriptAccess = "";
			this.f_in_box__control1.FlashProperty_BackgroundColor = -1;
			this.f_in_box__control1.FlashProperty_Base = "";
			this.f_in_box__control1.FlashProperty_BGColor = "";
			this.f_in_box__control1.FlashProperty_DeviceFont = false;
			this.f_in_box__control1.FlashProperty_EmbedMovie = false;
			this.f_in_box__control1.FlashProperty_FlashVars = "";
			this.f_in_box__control1.FlashProperty_FrameNum = -1;
			this.f_in_box__control1.FlashProperty_Loop = true;
			this.f_in_box__control1.FlashProperty_Menu = true;
			this.f_in_box__control1.FlashProperty_Movie = "";
			this.f_in_box__control1.FlashProperty_MovieData = "";
			this.f_in_box__control1.FlashProperty_Playing = true;
			this.f_in_box__control1.FlashProperty_Quality = 1;
			this.f_in_box__control1.FlashProperty_Quality2 = "High";
			this.f_in_box__control1.FlashProperty_SAlign = "";
			this.f_in_box__control1.FlashProperty_Scale = "ShowAll";
			this.f_in_box__control1.FlashProperty_ScaleMode = 0;
			this.f_in_box__control1.FlashProperty_Stacking = "";
			this.f_in_box__control1.FlashProperty_SWRemote = "";
			this.f_in_box__control1.FlashProperty_WMode = "Window";
			this.f_in_box__control1.Location = new System.Drawing.Point(8, 8);
			this.f_in_box__control1.Name = "f_in_box__control1";
			this.f_in_box__control1.Size = new System.Drawing.Size(616, 360);
			this.f_in_box__control1.StandardMenu = false;
			this.f_in_box__control1.TabIndex = 11;
			this.f_in_box__control1.Text = "f_in_box__control1";
			this.f_in_box__control1.OnIsInputKey += new f_in_box__lib.f_in_box__control.OnIsInputKeyHandler(this.f_in_box__control1_OnIsInputKey);
			this.f_in_box__control1.OnFlashCall += new f_in_box__lib.f_in_box__control.OnFlashCallEventHandler(this.f_in_box__control1_OnFlashCall);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(632, 446);
			this.Controls.Add(this.f_in_box__control1);
			this.Controls.Add(this.ButtonOrder);
			this.Controls.Add(this.ButtonAbout);
			this.Controls.Add(this.ButtonCallActionScriptFunction);
			this.MaximizeBox = false;
			this.Name = "MainForm";
			this.Text = "Sample 7 - Flash 8 External API";
			this.Load += new System.EventHandler(this.MainForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
            if (!f_in_box__lib.Global.IsFlashInstalled)
			{
				System.Windows.Forms.MessageBox.Show("The application needs Flash 8 or higher\nFlash is not installed");
				return;
			}

			if (f_in_box__lib.Global.InstalledFlashVersion.MajorPart < 8)
			{
				System.Windows.Forms.MessageBox.Show("The application needs Flash 8 or higher\nCurrent flash version is: " + f_in_box__lib.Global.InstalledFlashVersion.ToString());
				return;
			}

			Application.Run(new MainForm());
		}

		private void MainForm_Load(object sender, System.EventArgs e)
		{
			f_in_box__control1.PutMovieFromStream(this.GetType().Assembly.GetManifestResourceStream("Sample07_ExternalInterface.Embedded_Movies.externalinterface.swf"));
			f_in_box__control1.FlashMethod_Play();
		}

		private void ButtonCallActionScriptFunction_Click(object sender, System.EventArgs e)
		{
	        String Response = f_in_box__control1.FlashMethod_CallFunction("<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for F-IN-BOX .NET</string></arguments></invoke>");
		    System.Windows.Forms.MessageBox.Show("The function returned: '" + Response + "'", "Information");
		}

		private void MoreAboutComponentButton_Click(object sender, System.EventArgs e)
		{
			System.Diagnostics.Process.Start("http://www.f-in-box.com/dotnet/");
		}

		private void OrderButton_Click(object sender, System.EventArgs e)
		{
			System.Diagnostics.Process.Start("http://www.f-in-box.com/dotnet/order.html");
		}

		private void f_in_box__control1_OnFlashCall(object sender, string request)
		{
			f_in_box__control1.FlashMethod_SetReturnValue("<string>Current time is: " + System.DateTime.Now.ToString() + "</string>");
		}

		private void f_in_box__control1_OnIsInputKey(object sender, System.Windows.Forms.Keys keyData, ref bool InputKey)
		{
			if (keyData == System.Windows.Forms.Keys.Tab || 
				keyData == System.Windows.Forms.Keys.Enter || 
				keyData == System.Windows.Forms.Keys.Up || 
				keyData == System.Windows.Forms.Keys.Down || 
				keyData == System.Windows.Forms.Keys.Left || 
				keyData == System.Windows.Forms.Keys.Right)
				InputKey = true;
		}
	}
}
