using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using vclass.network.client;

namespace vclass.presentation
{
	/// <summary>
	/// Summary description for Form4.
	/// </summary>
	public class PresentationForm : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.PictureBox pictureBox1;
		private PresentationController pController = null;
		private int share = 0;

		public PresentationForm(MainForm mf)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			int x = this.Location.X + this.Size.Width;
			int y = this.Location.Y + this.Size.Height;
			pController = new PresentationController(this);
			pController.MdiParent = mf;	
			pController.Show();
			pController.SetBounds(this.Location.X, y, pController.Size.Width, pController.Size.Height);
			
			PresentationToolbox pToolbox = new PresentationToolbox(this);
			pToolbox.MdiParent = mf;
			pToolbox.Show();
			pToolbox.SetBounds(x, this.Location.Y, pToolbox.Size.Width, pToolbox.Size.Height);

			//
			// 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 );
		}

		public bool ThumbnailCallback()
		{
			return false;
		}

		public void setPicture(System.Drawing.Image pic)
		{
				System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);


			pictureBox1.Image = pic.GetThumbnailImage(pictureBox1.Size.Width,pictureBox1.Size.Height, myCallback, IntPtr.Zero);
			pictureBox1.Image.Save("c://slide_dnm.jpg");
			//pictureBox1.Scale(200, 200);
			if(share == 1)
			{
				ClassClient client = ((MainForm)this.MdiParent).getClient();
				client.sendSlide(pic);
			}
		}

		#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.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.pictureBox1.Location = new System.Drawing.Point(0, 0);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(376, 376);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			// 
			// PresentationForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(376, 376);
			this.ControlBox = false;
			this.Controls.Add(this.pictureBox1);
			this.Location = new System.Drawing.Point(200, 100);
			this.Name = "PresentationForm";
			this.Opacity = 0.5;
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.SizeChanged += new System.EventHandler(this.PresentationForm_SizeChanged);
			this.ResumeLayout(false);

		}
		#endregion

		private void PresentationForm_SizeChanged(object sender, System.EventArgs e)
		{
			pictureBox1.Size = this.Size;
			pController.loadSlide();
		}

		public void startSharing(){
			ClassClient client = ((MainForm)this.MdiParent).getClient();
			pictureBox1.Image.Save("c://slide_dnm.jpg");
			
			client.sendSlide(pictureBox1.Image);
			
			share = 1;
		}

		public void stopSharing(){
			share = 0;
		}
	}
}
