static void getValues(ZPoint p, Dictionary <char, char> cs)
 {
     foreach (char c in p.values)
     {
         if (cs.ContainsKey(c) == false)
         {
             cs.Add(c, c);
         }
     }
     if (p.dic.Count != 0)
     {
         foreach (KeyValuePair <char, ZPoint> kv in p.dic)
         {
             getValues(kv.Value, cs);
         }
     }
 }
        static ZPoint()
        {
            string path = System.IO.Directory.GetCurrentDirectory() + @"\WpfControlLibrary.data";

            string[] lines = File.ReadAllLines(path, Encoding.Default);
            foreach (string line in lines)
            {
                string[] datas = line.Split('=');
                int      i     = 0;
                ZPoint   p     = null;
                foreach (char c in datas[0])
                {
                    if (i == 0)
                    {
                        if (dic0.ContainsKey(c) == false)
                        {
                            dic0.Add(c, new ZPoint());
                            dic0[c].key = c;
                        }
                        p = dic0[c];
                    }
                    else
                    {
                        if (p.dic.ContainsKey(c) == false)
                        {
                            p.dic.Add(c, new ZPoint());
                            p.key = c;
                        }
                        p = p.dic[c];
                    }
                    i++;
                    if (i == datas[0].Length)
                    {
                        p.values.Add(datas[1][0]);
                    }
                }
            }
        }
        public static List <char> getValues(string pinyin)
        {
            if (pinyin.Length == 0)
            {
                return(new List <char>());
            }
            pinyin = pinyin.ToLower();
            ZPoint p = null;

            foreach (char c in pinyin)
            {
                if (p == null)
                {
                    if (dic0.ContainsKey(c) == false)
                    {
                        return(new List <char>());
                    }
                    p = dic0[c];
                    continue;
                }
                if (p.dic.ContainsKey(c))
                {
                    p = p.dic[c];
                }
            }
            Dictionary <char, char> cs = new Dictionary <char, char>();

            getValues(p, cs);
            List <char> cs2 = new List <char>();

            foreach (KeyValuePair <char, char> kv in cs)
            {
                cs2.Add(kv.Value);
            }
            return(cs2);
        }
Exemplo n.º 4
0
        private void WrapPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Controls.UserControl source = e.Source as System.Windows.Controls.UserControl;
            string tag = source.Tag.ToString();

            if (tag == "StyleButton")
            {
                StyleButton style  = source as StyleButton;
                string      txt    = style.Text1;
                bool        isLeft = style.isLeft();
                if (txt == "中文")
                {
                    ClearPinYin();
                    isChinese = !isChinese;
                }
                if (txt == "大写")
                {
                    foreach (KeyButton kb in kbs)
                    {
                        if (isUp)
                        {
                            kb.Text = kb.Text.ToLower();
                        }
                        else
                        {
                            kb.Text = kb.Text.ToUpper();
                        }
                    }
                    isUp = !isUp;
                }
                if (txt == "数字")
                {
                    foreach (CharacterButton cb in cbs)
                    {
                        cb.IsNum = !cb.IsNum;
                    }
                    isNum = !isNum;
                }
            }

            if (source.Tag.ToString() == "Key")
            {
                KeyButton kb   = source as KeyButton;
                string    text = kb.Text;
                //输入英文
                if (text.Length == 1 && isChinese == false)
                {
                    Send(text);
                    return;
                }
                text = text.ToLower();
                //打拼音
                if (text.Length == 1 && isChinese && pinyin.Text.Length < 6)
                {
                    List <char> cs = null;
                    pinyin.Text += text;
                    cs           = ZPoint.getValues(pinyin.Text);
                    page         = new PageHandle <char>(cs.ToArray(), 10);
                    bool   isStop = false;
                    char[] ca     = page.getFirstPage(out isStop);
                    SetSelectors(ca);
                }
                //删除拼音
                else if (text == "删除" && pinyin.Text.Length > 0)
                {
                    List <char> cs = null;
                    pinyin.Text = pinyin.Text.Substring(0, pinyin.Text.Length - 1);
                    cs          = ZPoint.getValues(pinyin.Text);
                    page        = new PageHandle <char>(cs.ToArray(), 10);
                    bool   isStop = false;
                    char[] ca     = page.getFirstPage(out isStop);
                    SetSelectors(ca);
                }
                //删除字
                else if (text == "删除")
                {
                    Send("{BACKSPACE}");
                }
                else if (text == "enter")
                {
                    if (pinyin.Text.Length != 0)
                    {
                        Send(pinyin.Text);
                        ClearPinYin();
                    }
                    else
                    {
                        Send("{ENTER}");
                    }
                }
                else if (text == "空格")
                {
                    if (pinyin.Text.Length != 0)
                    {
                        if (selectors[0].Visibility == Visibility.Visible)
                        {
                            Send(selectors[0].z);
                        }
                        ClearPinYin();
                    }
                    else
                    {
                        Send(" ");
                    }
                }
            }
            else if (source.Tag.ToString() == "Character")
            {
                CharacterButton cb = source as CharacterButton;
                string          t1 = cb.Text1;
                string          t2 = cb.Text2;
                //选择拼音结果
                if (pinyin.Text != "" && selectors[0].Visibility == Visibility.Visible)
                {
                    if (t1[0] >= '0' && t1[0] <= '9')
                    {
                        int index = int.Parse(t1);
                        foreach (One o in selectors)
                        {
                            if (o.num == t1 && o.Visibility == Visibility.Visible)
                            {
                                Send(o.z);
                                ClearPinYin();
                            }
                        }
                    }
                    else if (t1 == "<" && page != null)
                    {
                        bool   isSteop = false;
                        char[] ca      = page.getLastPage(out isSteop);
                        SetSelectors(ca);
                    }
                    else if (t1 == ">" && page != null)
                    {
                        bool   isStop = false;
                        char[] ca     = page.getNextPage(out isStop);
                        SetSelectors(ca);
                    }
                }
                else
                {
                    if (pinyin.Text != "")
                    {
                        pinyin.Text = "";
                    }
                    if (cb.IsNum)
                    {
                        Send(t1);
                    }
                    else
                    {
                        Send(t2);
                    }
                }
            }
        }