using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

namespace FLY.UI.OSK
{
    /// <summary>
    /// Window_FullPad.xaml 的交互逻辑
    /// </summary>
    public partial class Window_FullPad : Window,INotifyPropertyChanged
    {

        private System.Windows.Threading.DispatcherTimer timer;
        private TextBox textbox=null;


        FullKeyPad keypad;
        public Window_FullPad()
        {
            InitializeComponent();
            keypad = new FullKeyPad();

            timer = new System.Windows.Threading.DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(0.1);
            timer.Tick += new EventHandler(timer_Tick);
        }
        void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            this.ShowDialog();
        }

        public void Open(TextBox textbox)
        {
            
            this.textbox = textbox;
            this.Result = textbox.Text;
            timer.Start();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = keypad;
            this.textblock_result.DataContext = this;
        }

        private void button_q_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyQ;
        }

        private void button_w_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyW;
        }
        private void button_e_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyE;
        }
        private void button_r_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyR;
        }

        private void button_t_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyT;
        }

        private void button_y_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyY;
        }

        private void button_u_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyU;
        }

        private void button_i_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyI;
        }

        private void button_o_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyO;
        }

        private void button_p_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyP;
        }

        private void button_a_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyA;
        }

        private void button_s_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyS;
        }

        private void button_d_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyD;
        }

        private void button_f_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyF;
        }

        private void button_g_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyG;
        }

        private void button_h_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyH;
        }

        private void button_j_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyJ;
        }

        private void button_k_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyK;
        }

        private void button_l_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyL;
        }

        private void button_caps_Click(object sender, RoutedEventArgs e)
        {
            keypad.IsCapsLock = !keypad.IsCapsLock;
        }

        private void button_z_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyZ;
        }

        private void button_x_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyX;
        }

        private void button_c_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyC;
        }

        private void button_v_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyV;
        }

        private void button_b_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyB;
        }

        private void button_n_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyN;
        }

        private void button_m_Click(object sender, RoutedEventArgs e)
        {
            Result += keypad.KeyM;
        }

        private void button_backspace_Click(object sender, RoutedEventArgs e)
        {
            Result = "";
        }

        private void button_close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void button_123_Click(object sender, RoutedEventArgs e)
        {
            keypad.Is123 = !keypad.Is123;
        }

        private void button_space_Click(object sender, RoutedEventArgs e)
        {
            Result += " ";
        }

        private void button_enter_Click(object sender, RoutedEventArgs e)
        {
            if (this.textbox != null)
            {
                this.textbox.Text = Result;
            }
            this.Close();
        }



        string result;

        public string Result
        {
            get { return result; }
            set
            {
                if (result != value)
                {
                    result = value;
                    NotifyPropertyChanged("Result");
                }
            }
        }


        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }


    }
    public class FullKeyPad:INotifyPropertyChanged
    {

        string keyq;

        public string KeyQ
        {
            get { return keyq; }
            set
            {
                if (keyq != value)
                {
                    keyq = value;
                    NotifyPropertyChanged("KeyQ");
                }
            }
        }


        string keyw;

        public string KeyW
        {
            get { return keyw; }
            set
            {
                if (keyw != value)
                {
                    keyw = value;
                    NotifyPropertyChanged("KeyW");
                }
            }
        }


        string keye;

        public string KeyE
        {
            get { return keye; }
            set
            {
                if (keye != value)
                {
                    keye = value;
                    NotifyPropertyChanged("KeyE");
                }
            }
        }


        string keyr;

        public string KeyR
        {
            get { return keyr; }
            set
            {
                if (keyr != value)
                {
                    keyr = value;
                    NotifyPropertyChanged("KeyR");
                }
            }
        }


        string keyt;

        public string KeyT
        {
            get { return keyt; }
            set
            {
                if (keyt != value)
                {
                    keyt = value;
                    NotifyPropertyChanged("KeyT");
                }
            }
        }


        string keyy;

        public string KeyY
        {
            get { return keyy; }
            set
            {
                if (keyy != value)
                {
                    keyy = value;
                    NotifyPropertyChanged("KeyY");
                }
            }
        }


        string keyu;

        public string KeyU
        {
            get { return keyu; }
            set
            {
                if (keyu != value)
                {
                    keyu = value;
                    NotifyPropertyChanged("KeyU");
                }
            }
        }


        string keyi;

        public string KeyI
        {
            get { return keyi; }
            set
            {
                if (keyi != value)
                {
                    keyi = value;
                    NotifyPropertyChanged("KeyI");
                }
            }
        }


        string keyo;

        public string KeyO
        {
            get { return keyo; }
            set
            {
                if (keyo != value)
                {
                    keyo = value;
                    NotifyPropertyChanged("KeyO");
                }
            }
        }


        string keyp;

        public string KeyP
        {
            get { return keyp; }
            set
            {
                if (keyp != value)
                {
                    keyp = value;
                    NotifyPropertyChanged("KeyP");
                }
            }
        }


        string keya;

        public string KeyA
        {
            get { return keya; }
            set
            {
                if (keya != value)
                {
                    keya = value;
                    NotifyPropertyChanged("KeyA");
                }
            }
        }


        string keys;

        public string KeyS
        {
            get { return keys; }
            set
            {
                if (keys != value)
                {
                    keys = value;
                    NotifyPropertyChanged("KeyS");
                }
            }
        }


        string keyd;

        public string KeyD
        {
            get { return keyd; }
            set
            {
                if (keyd != value)
                {
                    keyd = value;
                    NotifyPropertyChanged("KeyD");
                }
            }
        }


        string keyf;

        public string KeyF
        {
            get { return keyf; }
            set
            {
                if (keyf != value)
                {
                    keyf = value;
                    NotifyPropertyChanged("KeyF");
                }
            }
        }


        string keyg;

        public string KeyG
        {
            get { return keyg; }
            set
            {
                if (keyg != value)
                {
                    keyg = value;
                    NotifyPropertyChanged("KeyG");
                }
            }
        }


        string keyh;

        public string KeyH
        {
            get { return keyh; }
            set
            {
                if (keyh != value)
                {
                    keyh = value;
                    NotifyPropertyChanged("KeyH");
                }
            }
        }


        string keyj;

        public string KeyJ
        {
            get { return keyj; }
            set
            {
                if (keyj != value)
                {
                    keyj = value;
                    NotifyPropertyChanged("KeyJ");
                }
            }
        }


        string keyk;

        public string KeyK
        {
            get { return keyk; }
            set
            {
                if (keyk != value)
                {
                    keyk = value;
                    NotifyPropertyChanged("KeyK");
                }
            }
        }

        

        string keyl;

        public string KeyL
        {
            get { return keyl; }
            set
            {
                if (keyl != value)
                {
                    keyl = value;
                    NotifyPropertyChanged("KeyL");
                }
            }
        }


        string keyz;

        public string KeyZ
        {
            get { return keyz; }
            set
            {
                if (keyz != value)
                {
                    keyz = value;
                    NotifyPropertyChanged("KeyZ");
                }
            }
        }


        string keyx;

        public string KeyX
        {
            get { return keyx; }
            set
            {
                if (keyx != value)
                {
                    keyx = value;
                    NotifyPropertyChanged("KeyX");
                }
            }
        }


        string keyc;

        public string KeyC
        {
            get { return keyc; }
            set
            {
                if (keyc != value)
                {
                    keyc = value;
                    NotifyPropertyChanged("KeyC");
                }
            }
        }


        string keyv;

        public string KeyV
        {
            get { return keyv; }
            set
            {
                if (keyv != value)
                {
                    keyv = value;
                    NotifyPropertyChanged("KeyV");
                }
            }
        }


        string keyb;

        public string KeyB
        {
            get { return keyb; }
            set
            {
                if (keyb != value)
                {
                    keyb = value;
                    NotifyPropertyChanged("KeyB");
                }
            }
        }



        string keyn;

        public string KeyN
        {
            get { return keyn; }
            set
            {
                if (keyn != value)
                {
                    keyn = value;
                    NotifyPropertyChanged("KeyN");
                }
            }
        }


        string keym;

        public string KeyM
        {
            get { return keym; }
            set
            {
                if (keym != value)
                {
                    keym = value;
                    NotifyPropertyChanged("KeyM");
                }
            }
        }


        bool isCapsLock;

        public bool IsCapsLock
        {
            get { return isCapsLock; }
            set
            {
                if (isCapsLock != value)
                {
                    isCapsLock = value;
                    NotifyPropertyChanged("IsCapsLock");
                }
            }
        }


        bool is123;

        public bool Is123
        {
            get { return is123; }
            set
            {
                if (is123 != value)
                {
                    is123 = value;
                    NotifyPropertyChanged("Is123");
                }
            }
        }

        
        

        public FullKeyPad()
        {
            IsCapsLock = false;
            Is123 = false;

            UpdateKey();

            this.PropertyChanged += new PropertyChangedEventHandler(FullKeyPad_PropertyChanged);
        }

        void FullKeyPad_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Is123")
            {
                UpdateKey();
            }
            if (e.PropertyName == "IsCapsLock")
            {
                UpdateKey();
            }
        }
        void UpdateKey() 
        {
            if (Is123)
            {
                To123();
            }
            else 
            {
                if (IsCapsLock)
                    ToUpper();
                else
                    ToLower();
            }
        }
        void To123() 
        {
            KeyQ = "1";
            KeyW = "2";
            KeyE = "3";
            KeyR = "4";
            KeyT = "5";
            KeyY = "6";
            KeyU = "7";
            KeyI = "8";
            KeyO = "9";
            KeyP = "0";
            KeyA = "!";
            KeyS = "@";
            KeyD = "#";
            KeyF = "$";
            KeyG = "%";
            KeyH = "&";
            KeyJ = "*";
            KeyK = "(";
            KeyL = ")";
            KeyZ = "'";
            KeyX = "/";
            KeyC = "-";
            KeyV = "_";
            KeyB = ":";
            KeyN = ";";
            KeyM = "?";
        }
        void ToUpper()
        {
            KeyQ = "Q";
            KeyW = "W";
            KeyE = "E";
            KeyR = "R";
            KeyT = "T";
            KeyY = "Y";
            KeyU = "U";
            KeyI = "I";
            KeyO = "O";
            KeyP = "P";
            KeyA = "A";
            KeyS = "S";
            KeyD = "D";
            KeyF = "F";
            KeyG = "G";
            KeyH = "H";
            KeyJ = "J";
            KeyK = "K";
            KeyL = "L";
            KeyZ = "Z";
            KeyX = "X";
            KeyC = "C";
            KeyV = "V";
            KeyB = "B";
            KeyN = "N";
            KeyM = "M";
        }
        void ToLower() 
        {
            KeyQ = "q";
            KeyW = "w";
            KeyE = "e";
            KeyR = "r";
            KeyT = "t";
            KeyY = "y";
            KeyU = "u";
            KeyI = "i";
            KeyO = "o";
            KeyP = "p";
            KeyA = "a";
            KeyS = "s";
            KeyD = "d";
            KeyF = "f";
            KeyG = "g";
            KeyH = "h";
            KeyJ = "j";
            KeyK = "k";
            KeyL = "l";
            KeyZ = "z";
            KeyX = "x";
            KeyC = "c";
            KeyV = "v";
            KeyB = "b";
            KeyN = "n";
            KeyM = "m";
        }
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;
    }
}
