Exemplo n.º 1
0
        public bool Income(int vkCode)
        {
            try
            {
                Buffer bf = new Buffer();
                string input = ((Keys)vkCode).ToString();
                int num = isNumber(vkCode);
                if (num > 0 && KeyCaches != null && num <= KeyCaches.Count)
                {
                    imf.Hide();
                    KeyCacher kch = (KeyCacher)KeyCaches[num - 1];
                    SendCH.Del(kch.match.Length);
                    KeyCacher sch = CaculatePossibleStaking(bf, kch.value);
                    //List<KeyCacher> suggestions = CaculatePossibleSuggestions(bf, kch.value);
                    if (sch != null)
                    {
                        KeyCaches = new ArrayList();
                        KeyCacher lx = new KeyCacher();
                        lx.num = 1;
                        lx.value = sch.value;
                        lx.match = sch.match;
                        KeyCaches.Add(lx);
                        imf.SetText("1. " + sch.value);
                        FindCaretAndShow();
                        //bf.Append(kch.value);
                        tmp = new StringBuilder();
                        //SendCH.Send(kch.value);
                        foreach (char c in kch.value)
                        {
                            if (c != '\u200b')
                                iop.Income(c.ToString());
                        }
                        return false;
                    }
                    else
                    {
                        //bf.Append(kch.value);
                        tmp = new StringBuilder();
                        string res = Preprocess(kch.value);
                        foreach (char c in res)
                        {
                            if (c != '\u200b')
                            {
                                foreach (string ch in iop.CompatibilityDecompose(c.ToString()))
                                {
                                    iop.Income(ch);
                                }
                            }
                        }
                        //SendCH.Send(kch.value);
                        KeyCaches = null;
                        return false;
                    }
                }
                else if (vkCode == 0x20 || vkCode == 0x0d)
                {
                    if (KeyCaches != null)
                    {
                        imf.Hide();
                        KeyCacher kch = (KeyCacher)KeyCaches[0];
                        SendCH.Del(kch.match.Length);
                        KeyCacher sch = CaculatePossibleStaking(bf, kch.value);
                        if (sch != null)
                        {
                            KeyCaches = new ArrayList();
                            KeyCacher lx = new KeyCacher();
                            lx.num = 1;
                            lx.value = sch.value;
                            lx.match = sch.match;
                            KeyCaches.Add(lx);
                            imf.SetText("1. " + sch.value);
                            //imf.Show();
                            FindCaretAndShow();
                            //bf.Append(kch.value);
                            tmp = new StringBuilder();
                            //SendCH.Send(kch.value);
                            foreach (char c in kch.value)
                            {
                                if (c != '\u200b')
                                    iop.Income(c.ToString());
                            }
                            return false;
                        }
                        else
                        {
                            //bf.Append(kch.value);
                            tmp = new StringBuilder();
                            //SendCH.Send(kch.value);
                            string res = Preprocess(kch.value);
                            foreach (char c in res)
                            {
                                if (c != '\u200b')
                                {
                                    foreach (string ch in iop.CompatibilityDecompose(c.ToString()))
                                    {
                                        iop.Income(ch);
                                    }
                                }
                            }
                            KeyCaches = null;
                            return false;
                        }
                    }
                    if (vkCode == 0x0d)
                        mfm.SystemKeyEvent();
                    tmp = new StringBuilder();
                    return true;
                }
                else if (vkCode == 0x1b)
                {
                    KeyCaches = null;
                    tmp = new StringBuilder();
                    imf.Hide();
                    return false;
                }
                else
                {
                    if (vkCode == 0x08)
                    {


                        if (tmp.Length > 0)
                            tmp.Remove(tmp.Length - 1, 1);
                        else if (tmp.Length == 0)
                        {
                            imf.Hide();
                            string buffer = bf.getBuffer();
                            if (buffer.Length > 0)
                            {
                                int x = 0;
                                for (int i = buffer.Length - 2; i >= 0; i--)
                                {
                                    x++;
                                    if (buffer[i] == 0x200b)
                                    {
                                        SendCH.Del(x);
                                        bf.PopChars(x);
                                        return false;
                                    }
                                }
                                if (buffer[buffer.Length - 1] == '\u200b')
                                {
                                    bf.PopChars(buffer.Length);
                                    SendCH.Del(buffer.Length);
                                }
                                else
                                {
                                    bf.PopChars(1);
                                    SendCH.Del(1);
                                }

                                return false;
                            }
                        }
                    }
                    else
                    {
                        if (input.Length > 1)
                        {
                            if (input == "Oemtilde")
                                tmp.Append("`");
                            else if (input.StartsWith("D") && input.Length == 2)
                            {
                                tmp.Append(input[1]);
                            }
                            else if (input == "Oem1")
                            {
                                tmp.Append(";");
                            }
                            else if (input == "Oemcomma")
                            {
                                tmp.Append(",");
                            }
                            else if (input == "OemPeriod")
                            {
                                tmp.Append(".");
                            }
                            else if (input == "OemQuestion")
                            {
                                tmp.Append("/");
                            }
                            else
                            {
                                tmp.Append('-');
                            }
                        }
                        else
                        {
                            tmp.Append(input);
                        }
                    }
                    ArrayList al = new ArrayList();
                    IMEData s = kime.getData(tmp.ToString());
                    if (s != null)
                    {
                        KeyCaches = new ArrayList();
                        string str = "";
                        for (int i = 0; i < s.Values.Count; i++)
                        {
                            KeyCacher kch = new KeyCacher();
                            kch.num = i + 1;
                            kch.value = s.Values[i].ToString();
                            kch.match = s.key;
                            KeyCaches.Add(kch);
                            str += (i + 1).ToString() + ". " + s.Values[i].ToString() + "  ";
                        }
                        imf.SetText(str);
                        FindCaretAndShow();
                        /*Point p = FindCaret();
                        BackupState();
                            imf.ShowFormAt(p.X, p.Y - imf.Height);
                        RestoreState();
                         //*/
                    }
                    else
                    {
                        imf.Hide();
                        KeyCaches = null;
                    }
                    return true;
                }
            }
            catch { return true; }
        }
Exemplo n.º 2
0
        public bool Income(int vkCode)
        {
            try
            {
                Buffer bf    = new Buffer();
                string input = ((Keys)vkCode).ToString();
                int    num   = isNumber(vkCode);
                if (num > 0 && KeyCaches != null && num <= KeyCaches.Count)
                {
                    imf.Hide();
                    KeyCacher kch = (KeyCacher)KeyCaches[num - 1];
                    SendCH.Del(kch.match.Length);
                    KeyCacher sch = CaculatePossibleStaking(bf, kch.value);
                    //List<KeyCacher> suggestions = CaculatePossibleSuggestions(bf, kch.value);
                    if (sch != null)
                    {
                        KeyCaches = new ArrayList();
                        KeyCacher lx = new KeyCacher();
                        lx.num   = 1;
                        lx.value = sch.value;
                        lx.match = sch.match;
                        KeyCaches.Add(lx);
                        imf.SetText("1. " + sch.value);
                        FindCaretAndShow();
                        //bf.Append(kch.value);
                        tmp = new StringBuilder();
                        //SendCH.Send(kch.value);
                        foreach (char c in kch.value)
                        {
                            if (c != '\u200b')
                            {
                                iop.Income(c.ToString());
                            }
                        }
                        return(false);
                    }
                    else
                    {
                        //bf.Append(kch.value);
                        tmp = new StringBuilder();
                        string res = Preprocess(kch.value);
                        foreach (char c in res)
                        {
                            if (c != '\u200b')
                            {
                                foreach (string ch in iop.CompatibilityDecompose(c.ToString()))
                                {
                                    iop.Income(ch);
                                }
                            }
                        }
                        //SendCH.Send(kch.value);
                        KeyCaches = null;
                        return(false);
                    }
                }
                else if (vkCode == 0x20 || vkCode == 0x0d)
                {
                    if (KeyCaches != null)
                    {
                        imf.Hide();
                        KeyCacher kch = (KeyCacher)KeyCaches[0];
                        SendCH.Del(kch.match.Length);
                        KeyCacher sch = CaculatePossibleStaking(bf, kch.value);
                        if (sch != null)
                        {
                            KeyCaches = new ArrayList();
                            KeyCacher lx = new KeyCacher();
                            lx.num   = 1;
                            lx.value = sch.value;
                            lx.match = sch.match;
                            KeyCaches.Add(lx);
                            imf.SetText("1. " + sch.value);
                            //imf.Show();
                            FindCaretAndShow();
                            //bf.Append(kch.value);
                            tmp = new StringBuilder();
                            //SendCH.Send(kch.value);
                            foreach (char c in kch.value)
                            {
                                if (c != '\u200b')
                                {
                                    iop.Income(c.ToString());
                                }
                            }
                            return(false);
                        }
                        else
                        {
                            //bf.Append(kch.value);
                            tmp = new StringBuilder();
                            //SendCH.Send(kch.value);
                            string res = Preprocess(kch.value);
                            foreach (char c in res)
                            {
                                if (c != '\u200b')
                                {
                                    foreach (string ch in iop.CompatibilityDecompose(c.ToString()))
                                    {
                                        iop.Income(ch);
                                    }
                                }
                            }
                            KeyCaches = null;
                            return(false);
                        }
                    }
                    if (vkCode == 0x0d)
                    {
                        mfm.SystemKeyEvent();
                    }
                    tmp = new StringBuilder();
                    return(true);
                }
                else if (vkCode == 0x1b)
                {
                    KeyCaches = null;
                    tmp       = new StringBuilder();
                    imf.Hide();
                    return(false);
                }
                else
                {
                    if (vkCode == 0x08)
                    {
                        if (tmp.Length > 0)
                        {
                            tmp.Remove(tmp.Length - 1, 1);
                        }
                        else if (tmp.Length == 0)
                        {
                            imf.Hide();
                            string buffer = bf.getBuffer();
                            if (buffer.Length > 0)
                            {
                                int x = 0;
                                for (int i = buffer.Length - 2; i >= 0; i--)
                                {
                                    x++;
                                    if (buffer[i] == 0x200b)
                                    {
                                        SendCH.Del(x);
                                        bf.PopChars(x);
                                        return(false);
                                    }
                                }
                                if (buffer[buffer.Length - 1] == '\u200b')
                                {
                                    bf.PopChars(buffer.Length);
                                    SendCH.Del(buffer.Length);
                                }
                                else
                                {
                                    bf.PopChars(1);
                                    SendCH.Del(1);
                                }

                                return(false);
                            }
                        }
                    }
                    else
                    {
                        if (input.Length > 1)
                        {
                            if (input == "Oemtilde")
                            {
                                tmp.Append("`");
                            }
                            else if (input.StartsWith("D") && input.Length == 2)
                            {
                                tmp.Append(input[1]);
                            }
                            else if (input == "Oem1")
                            {
                                tmp.Append(";");
                            }
                            else if (input == "Oemcomma")
                            {
                                tmp.Append(",");
                            }
                            else if (input == "OemPeriod")
                            {
                                tmp.Append(".");
                            }
                            else if (input == "OemQuestion")
                            {
                                tmp.Append("/");
                            }
                            else
                            {
                                tmp.Append('-');
                            }
                        }
                        else
                        {
                            tmp.Append(input);
                        }
                    }
                    ArrayList al = new ArrayList();
                    IMEData   s  = kime.getData(tmp.ToString());
                    if (s != null)
                    {
                        KeyCaches = new ArrayList();
                        string str = "";
                        for (int i = 0; i < s.Values.Count; i++)
                        {
                            KeyCacher kch = new KeyCacher();
                            kch.num   = i + 1;
                            kch.value = s.Values[i].ToString();
                            kch.match = s.key;
                            KeyCaches.Add(kch);
                            str += (i + 1).ToString() + ". " + s.Values[i].ToString() + "  ";
                        }
                        imf.SetText(str);
                        FindCaretAndShow();

                        /*Point p = FindCaret();
                         * BackupState();
                         *  imf.ShowFormAt(p.X, p.Y - imf.Height);
                         * RestoreState();
                         * //*/
                    }
                    else
                    {
                        imf.Hide();
                        KeyCaches = null;
                    }
                    return(true);
                }
            }
            catch { return(true); }
        }
Exemplo n.º 3
0
 private KeyCacher CaculatePossibleStaking(Buffer bf, string p)
 {
     KeyCacher kch = new KeyCacher();
     string b = bf.getBuffer();
     if (b.Length > 0 && b[b.Length - 1]==(char)0x200b)
     {
         b = b.Substring(0, b.Length - 1);
         int ee = b.LastIndexOf((char)0x200b);
         if (ee > 0 && ee != b.Length - 1)
             b = b.Substring(ee + 1);
         b += (char)0x200b;
     }
     if (b.Contains("\u1039"))
     {
     }else if (b.Length > 1)
     {
         if (b[b.Length - 1] == 0x200b)
         {
             if (isConsonant(b[b.Length - 2]))
             {
                 if (isConsonant(p[0]))
                 {
                     if (doesStack(b[b.Length - 2], p[0]))
                     {
                         string left = b;
                         left = left.Substring(0, left.Length - 1);
                         int i = left.LastIndexOf((char)0x200b);
                         if(i>0)
                             left = left.Substring(i+1);
                         kch.value = left + (char)0x1039 +  p;
                         kch.match = b + p;
                         return kch;
                     }
                 }
             }
             else if (b.Length > 2)
             {
                 if (isConsonant(b[b.Length - 3]))
                 {
                     if (b[b.Length - 3] == 'င')
                     {
                         if (isConsonant(p[0]))
                         {
                             if (doesStack(b[b.Length - 3], p[0]))
                             {
                                 string left = b.ToString();
                                 left = left.Substring(0, left.Length - 1);
                                 int i = left.LastIndexOf((char)0x200b);
                                 if (i > 0)
                                     left = left.Substring(i + 1);
                                 kch.value = left + (char)0x1039 + p;
                                 kch.match = b + p;
                                 return kch;
                             }
                         }
                     }
                     else
                     {
                         if (b[b.Length - 2] == (char)0x103a)
                         {
                             if (isConsonant(p[0]))
                             {
                                 if (doesStack(b[b.Length - 3], p[0]))
                                 {
                                     string left = b.ToString();
                                     left = left.Substring(0, left.Length - 2);
                                     int i = left.LastIndexOf((char)0x200b);
                                     if (i > 0)
                                         left = left.Substring(i + 1);
                                     kch.value = left + (char)0x1039 + p;
                                     kch.match = b + p;
                                     return kch;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return null;
 }
Exemplo n.º 4
0
        private KeyCacher CaculatePossibleStaking(Buffer bf, string p)
        {
            KeyCacher kch = new KeyCacher();
            string    b   = bf.getBuffer();

            if (b.Length > 0 && b[b.Length - 1] == (char)0x200b)
            {
                b = b.Substring(0, b.Length - 1);
                int ee = b.LastIndexOf((char)0x200b);
                if (ee > 0 && ee != b.Length - 1)
                {
                    b = b.Substring(ee + 1);
                }
                b += (char)0x200b;
            }
            if (b.Contains("\u1039"))
            {
            }
            else if (b.Length > 1)
            {
                if (b[b.Length - 1] == 0x200b)
                {
                    if (isConsonant(b[b.Length - 2]))
                    {
                        if (isConsonant(p[0]))
                        {
                            if (doesStack(b[b.Length - 2], p[0]))
                            {
                                string left = b;
                                left = left.Substring(0, left.Length - 1);
                                int i = left.LastIndexOf((char)0x200b);
                                if (i > 0)
                                {
                                    left = left.Substring(i + 1);
                                }
                                kch.value = left + (char)0x1039 + p;
                                kch.match = b + p;
                                return(kch);
                            }
                        }
                    }
                    else if (b.Length > 2)
                    {
                        if (isConsonant(b[b.Length - 3]))
                        {
                            if (b[b.Length - 3] == 'င')
                            {
                                if (isConsonant(p[0]))
                                {
                                    if (doesStack(b[b.Length - 3], p[0]))
                                    {
                                        string left = b.ToString();
                                        left = left.Substring(0, left.Length - 1);
                                        int i = left.LastIndexOf((char)0x200b);
                                        if (i > 0)
                                        {
                                            left = left.Substring(i + 1);
                                        }
                                        kch.value = left + (char)0x1039 + p;
                                        kch.match = b + p;
                                        return(kch);
                                    }
                                }
                            }
                            else
                            {
                                if (b[b.Length - 2] == (char)0x103a)
                                {
                                    if (isConsonant(p[0]))
                                    {
                                        if (doesStack(b[b.Length - 3], p[0]))
                                        {
                                            string left = b.ToString();
                                            left = left.Substring(0, left.Length - 2);
                                            int i = left.LastIndexOf((char)0x200b);
                                            if (i > 0)
                                            {
                                                left = left.Substring(i + 1);
                                            }
                                            kch.value = left + (char)0x1039 + p;
                                            kch.match = b + p;
                                            return(kch);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }