Exemplo n.º 1
0
        // Process response by background system.
        private static void processResponse(string res)
        {
            string[] seperator = new string[] { "\n" };
            string[] parts     = res.Split(seperator, StringSplitOptions.None);
            // Extract Communication code.
            int commCode = Int32.Parse(parts[0]);

            // According to Communication code, do actions.
            switch (commCode)
            {
            case ALL_OK:
            {
                break;
            }

            case RECEIVED:
            {
                break;
            }

            case HOT_KEY:
            {
                serverStat  = CONNECTED;
                isHotkeyGet = true;
                string[] newSep = new string[] { "%" };
                for (int i = 1; i < parts.Length; i++)
                {
                    String[] temp   = parts[i].Split(newSep, StringSplitOptions.None);
                    int[]    intRes = new int[3];
                    for (int j = 0; j < temp.Length; j++)
                    {
                        temp[j]   = temp[j].Substring(2);
                        intRes[j] = Convert.ToInt32(temp[j], 16);
                    }
                    if (temp.Length < 3)
                    {
                        intRes[2] = -1;
                    }

                    switch (i)
                    {
                    case 1:
                    {
                        InputDetector.extendSentenceHotKey = intRes;
                        break;
                    }

                    case 2:
                    {
                        InputDetector.deleteSentenceHotKey = intRes;
                        break;
                    }

                    case 3:
                    {
                        InputDetector.extendParaHotKey = intRes;
                        break;
                    }

                    case 4:
                    {
                        InputDetector.deleteParaHotKey = intRes;
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }

                    Messenger.message(intRes[0].ToString() + " " + intRes[1].ToString() + " " + intRes[2].ToString());
                }
                break;
            }

            case PREFERENCE_LIST:
            {
                result = new List <Preference>();
                for (int i = 1; i < parts.Length; i++)
                {
                    Preference tempPref = new Preference();
                    tempPref.setID(i);
                    tempPref.setContent(parts[i]);
                    result.Add(tempPref);
                }
                break;
            }

            default:
            {
                serverStat = UNCONNECTED;
                break;
            }
            }
            ;
        }
Exemplo n.º 2
0
        // Process response by background system.
        private static void processResponse(string res)
        {
            string[] seperator = new string[] { "\n" };
            string[] parts = res.Split(seperator, StringSplitOptions.None);
            // Extract Communication code.
            int commCode = Int32.Parse(parts[0]);
            // According to Communication code, do actions.
            switch (commCode)
            {
                case ALL_OK:
                    {
                        break;
                    }
                case RECEIVED:
                    {
                        break;
                    }
                case HOT_KEY:
                    {
                        serverStat = CONNECTED;
                        isHotkeyGet = true;
                        string[] newSep = new string[] {"%"};
                        for (int i = 1; i < parts.Length; i++)
                        {
                            String[] temp = parts[i].Split(newSep, StringSplitOptions.None);
                            int[] intRes = new int[3];
                            for (int j = 0; j < temp.Length; j++)
                            {
                                temp[j] = temp[j].Substring(2);
                                intRes[j] = Convert.ToInt32(temp[j], 16);
                            }
                            if (temp.Length < 3) intRes[2] = -1;

                            switch (i)
                            {
                                case 1:
                                    {
                                        InputDetector.extendSentenceHotKey = intRes;
                                        break;
                                    }
                                case 2:
                                    {
                                        InputDetector.deleteSentenceHotKey = intRes;
                                        break;
                                    }
                                case 3:
                                    {
                                        InputDetector.extendParaHotKey = intRes;
                                        break;
                                    }
                                case 4:
                                    {
                                        InputDetector.deleteParaHotKey = intRes;
                                        break;
                                    }
                                default:
                                    {
                                        break;
                                    }
                            }

                            Messenger.message(intRes[0].ToString() + " " + intRes[1].ToString() + " " + intRes[2].ToString());
                        }
                        break;
                    }
                case PREFERENCE_LIST:
                    {
                        result = new List<Preference>();
                        for (int i = 1; i < parts.Length; i++)
                        {
                            Preference tempPref = new Preference();
                            tempPref.setID(i);
                            tempPref.setContent(parts[i]);
                            result.Add(tempPref) ;
                        }
                        break;
                    }
                default:
                    {
                        serverStat = UNCONNECTED;
                        break;
                    }
            };
        }
Exemplo n.º 3
0
        private void PrefList_DrawItem(object sender, DrawItemEventArgs e)
        {
            bool selected = false;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                e = new DrawItemEventArgs(e.Graphics,
                                          e.Font,
                                          e.Bounds,
                                          e.Index,
                                          e.State ^ DrawItemState.Selected,
                                          e.ForeColor,
                                          Color.FromArgb(51, 153, 255));//Choose the color
                selected = true;
                // Draw the selected background
                e.DrawBackground();
            }
            else
            {
                if (e.Index % 2 == 1)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(239, 248, 253)), e.Bounds);
                }
                else
                {
                    // Draw the default background
                    e.DrawBackground();
                }
            }

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();

            if (e.Index >= 0)
            {
                Preference suggestion = (Preference)PrefList.Items[e.Index];
                String     content = suggestion.getContent(), sourceName = suggestion.getSource();

                content = content.Replace("\n", " ");

                Rectangle drawBound = e.Bounds;
                drawBound.X      += padding;
                drawBound.Y      += padding;
                drawBound.Width  -= padding * 2;
                drawBound.Height -= padding * 2;

                StringFormat stringFormat = StringFormat.GenericDefault;
                stringFormat.Alignment = StringAlignment.Near;

                // Draw Index String
                Brush myBrush = new SolidBrush(Color.FromArgb(102, 106, 114));
                if (selected)
                {
                    myBrush = Brushes.White;
                }
                Font font = new Font(e.Font.FontFamily, e.Font.Size + 6, e.Font.Style);
                drawBound.Y += 2;
                e.Graphics.DrawString((e.Index + 1) + "", font, myBrush, drawBound, stringFormat);
                drawBound.Y -= 2;

                // Draw Content String
                myBrush = Brushes.Black;
                if (selected)
                {
                    myBrush = Brushes.White;
                }
                font             = new Font(e.Font.FontFamily, e.Font.Size + 1, e.Font.Style);
                content          = getSuggestionWrapping(content, font, false);
                drawBound.X     += 18;
                drawBound.Width -= 18;

                e.Graphics.DrawString(content, font, myBrush, drawBound, stringFormat);

                drawBound.Y      += getRenderTextHeight(content, PrefList, font);
                drawBound.Height -= getRenderTextHeight(content, PrefList, font);

                myBrush    = new SolidBrush(Color.FromArgb(54, 96, 137));
                font       = new Font(e.Font.FontFamily, e.Font.Size - 1, e.Font.Style);
                sourceName = getSourceNameWrapping(sourceName, font);
                if (selected)
                {
                    myBrush = Brushes.White;
                }

                e.Graphics.DrawString(sourceName, font, myBrush, drawBound, StringFormat.GenericDefault);

                // Draw bottom line if it is not the last entry
                if (e.Index != PrefList.Items.Count - 1)
                {
                    Pen   pen    = new Pen(Color.FromArgb(185, 187, 189), 1);
                    Point point1 = new Point(0, e.Bounds.Y + e.Bounds.Height - 1);
                    Point point2 = new Point(e.Bounds.X + e.Bounds.Width - 1, e.Bounds.Y + e.Bounds.Height - 1);
                    e.Graphics.DrawLine(pen, point1, point2);
                }
            }

            e.DrawFocusRectangle();
        }