//ライセンス情報はAgeOnフォルダのLISENCEフォルダを参照してください
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using MecInfoDll;
using System.Runtime.InteropServices;
using System.Linq;


namespace nispi
{
    class ProgressBarForm
    {
        public Form popUp;
        public Label textLabel;
        public ProgressBar progressBar;
        public Button exitButton;

        public delegate void SimpleMethod();
        public SimpleMethod closeDele;

        public ProgressBarForm(SimpleMethod method)
        {
            this.closeDele = method;

            //フォーム
            popUp = new Form();
            popUp.Hide();
            popUp.StartPosition = FormStartPosition.Manual;
            /*popUp.Location =
                ViewMediator.worldMapMain.worldMapControlView.panelMap.PointToScreen(
                ViewMediator.worldMapMain.worldMapControlView.panelMap.Location);*/
            popUp.Size = new Size(350, 180);
            popUp.MaximumSize = new Size(350, 180);
            popUp.MinimumSize = new Size(350, 180);
            popUp.Text = "ダウンロード中です";
            //popUp.Owner = Const.form.mainForm.control;

            popUp.FormClosing += new FormClosingEventHandler(popUp_FormClosing);
            //ラベル
            textLabel = new Label();
            textLabel.Location = new System.Drawing.Point(50, 15);
            textLabel.Name = "Label1";
            textLabel.Size = new System.Drawing.Size(300, 30);
            textLabel.TabIndex = 0;
            //textLabel.Text = "受信しています";

            //プログレスバー
            progressBar = new ProgressBar();
            progressBar.Location = new System.Drawing.Point(25, 50);
            progressBar.Name = "ProgressBar1";
            progressBar.Size = new System.Drawing.Size(290, 25);
            progressBar.TabIndex = 1;
            progressBar.Minimum = 0;

            exitButton = new Button();
            exitButton.Location = new Point(130, 90);
            exitButton.AutoSize = true;
            exitButton.Text = "中止する";
            exitButton.Click += new EventHandler(exitButton_Click);

            popUp.Controls.Add(textLabel);
            popUp.Controls.Add(progressBar);
            popUp.Controls.Add(exitButton);
        }

        public void SetUpTwo()
        {
            popUp.Location = new Point(
                Const.mapForm.mapMainForm.Location.X + Const.mapForm.mapMainForm.Size.Width / 2,
                Const.mapForm.mapMainForm.Location.Y + Const.mapForm.mapMainForm.Size.Height / 2);
            progressBar.Value = 0;
            popUp.ShowDialog();
        }

        private void popUp_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            if (popUp.Visible == true)
            {
                Const.form.mainForm.BeginInvoke((Action)(() => this.closeDele()));
                //Closing();
            }
        }

        //呼び出し側のクロース処理を行う
        private void exitButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (popUp.Visible == true)
                {
                    Const.form.mainForm.BeginInvoke((Action)(() => this.closeDele()));
                    //Closing();
                }
            }
            catch { ;}
        }
        //ウィンドウを隠す
        public void Closing()
        {
            popUp.Hide();
            popUp.Dispose();
            progressBar.Dispose();
            textLabel.Dispose();
            textLabel.Dispose();
            closeDele = null;


        }
    }
}
