using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace INT69DC_7C.DialogForms
{
    public partial class DialogFormUserEditorKeyboard : Form
    {
        #region Field
        private string m_RetStringValue;
        #endregion

        #region Constructor
        public DialogFormUserEditorKeyboard(string value)
        {
            InitializeComponent();

            this.textBox.Text = value;
            this.RetStringValue = value;

            this.InitializeControl();
            this.DefaultSetting();
        } 
        #endregion
      
        #region Property
        public string RetStringValue
        {
            get { return this.m_RetStringValue; }
            private set { this.m_RetStringValue = value; }
        }
        #endregion

        #region Method
        private void InitializeControl()
        {
            int x = 0, y = 0;

            x = Screen.PrimaryScreen.Bounds.Width / 2 - this.Size.Width / 2;
            y = Screen.PrimaryScreen.Bounds.Height / 2 - this.Size.Height / 2;

            this.Location = new Point(x, y);
            this.Size = new Size(710, 470);
        }
        private void DefaultSetting()
        {
            this.smartKeyboard.TargetInputObject = this.textBox;
            this.smartKeyboard.KeyboardType = SmartX.SmartKeyboard.KEYBOARDTYPES.NORMAL;
            this.smartKeyboard.Show();
        }

        private void KeyActionEnter()
        {
            this.RetStringValue = this.textBox.Text;

            this.DialogResult = DialogResult.OK;
            this.Close();
            this.Dispose();
        }
        private void KeyActionEsc()
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
            this.Dispose();
        }
        #endregion

        #region Event Handler
        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '<' || e.KeyChar == '>' || e.KeyChar == '|' || e.KeyChar == '"' || e.KeyChar == '?'
                || e.KeyChar == ':' || e.KeyChar == '/' || e.KeyChar == '\\' || e.KeyChar == ',' || e.KeyChar == ';'
                || e.KeyChar == '`' || e.KeyChar == '=' || e.KeyChar == '(' || e.KeyChar == ')' || e.KeyChar == '{' || e.KeyChar == '}'
                || e.KeyChar == '~' || e.KeyChar == '_' || e.KeyChar == '[' || e.KeyChar == ']' || e.KeyChar == '\'')
            {
                e.Handled = true;
            }
        }

        private void smartKeyboard_OnXKeyClick(object sender, EventArgs e)
        {
            this.KeyActionEsc();
        }
        private void smartKeyboard_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                this.KeyActionEnter();
            else if (e.KeyCode == Keys.Escape)
                this.KeyActionEsc();
        }
        #endregion
    }
}