using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Janus.Windows.EditControls;

namespace IControls_FireManager
{
    // 크로스 스레드 에러 문제 해결 :

    public static class _Crossthread
    {
        ///
        /// CallBack Attribute
        ///

        // 폼의 텍스트를 변경하는 경우 
        delegate void CallBack_Form_SetText(Form target, string text);
        // 폼을 나타내는 경우 
        delegate void CallBack_Form_Show(Form target);
        // 컨트롤 텍스트를 변경하는 경우 (일반 텍스트박스 혹은 라벨이 해당됨)
        delegate void CallBack_Control_SetText(Control target, string text);
        // 컨트롤 활성화를 변경하는 경우
        delegate void CallBack_Control_SetEnable(Control target, bool Enable);
        // 컨트롤 포커스를 지정하는 경우
        delegate void CallBack_Control_SetFocus(Control target);        
        // 프로그레스바의 값을 변경하는 경우
        delegate void CallBack_UIProgressBar_Value(UIProgressBar target, int Value);
       
        ///
        /// Target UI : Form
        ///

        public static void Form_SetText(Form target, string text)
        {
            if (target.InvokeRequired)
            {
                CallBack_Form_SetText d = new CallBack_Form_SetText(Form_SetText);
                target.Invoke(d, new object[] { target, text });
            }
            else
            {
                target.Text = text;
            }
        }

        public static void Form_Close(Form target)
        {
            if (target.InvokeRequired)
            {
                CallBack_Form_Show d = new CallBack_Form_Show(Form_Show);
                target.Invoke(d, new object[] { target });
            }
            else
            {
                target.Close();
            }
        }

        public static void Form_Show(Form target)
        {
            if (target.InvokeRequired)
            {
                CallBack_Form_Show d = new CallBack_Form_Show(Form_Show);
                target.Invoke(d, new object[] { target });
            }
            else
            {
                target.Show();
            }
        }

        public static void Form_Hide(Form target)
        {
            if (target.InvokeRequired)
            {
                CallBack_Form_Show d = new CallBack_Form_Show(Form_Show);
                target.Invoke(d, new object[] { target });
            }
            else
            {
                target.Hide();
            }
        }

        ///
        /// Target UI : Control
        ///

        public static void Control_SetText(Control target, string text)
        {
            if (target.InvokeRequired)
            {
                CallBack_Control_SetText d = new CallBack_Control_SetText(Control_SetText);
                target.Invoke(d, new object[] { target, text });
            }
            else
            {
                target.Text = text;
            }
        }

        public static void Control_SetEnable(Control target, bool Enable)
        {
            if (target.InvokeRequired)
            {
                CallBack_Control_SetEnable d = new CallBack_Control_SetEnable(Control_SetEnable);
                target.Invoke(d, new object[] { target, Enable });
            }
            else
            {
                target.Enabled = Enable;
            }
        }

        public static void Control_SetFocus(Control target)
        {
            if (target.InvokeRequired)
            {
                CallBack_Control_SetFocus d = new CallBack_Control_SetFocus(Control_SetFocus);
                target.Invoke(d, new object[] { target });
            }
            else
            {
                target.Focus();
            }
        }

        ///
        /// Target UI : UIProgressBar
        ///

        public static void UIProgressBar_SetValue(UIProgressBar target, int Value)
        {
            if (target.InvokeRequired)
            {
                CallBack_UIProgressBar_Value d = new CallBack_UIProgressBar_Value(UIProgressBar_SetValue);
                target.Invoke(d, new object[] { target, Value });
            }
            else
            {
                target.Value = Value;
            }
        }

      
    }
}