Example #1
0
        void Chat_Update(ChatMessage message)
        {
            int oldStart  = MessageTextBox.SelectionStart;
            int oldLength = MessageTextBox.SelectionLength;

            MessageTextBox.SelectionStart  = MessageTextBox.Text.Length;
            MessageTextBox.SelectionLength = 0;

            // name, in bold, blue for incoming, red for outgoing
            if (message.System)
            {
                MessageTextBox.SelectionColor = Color.Black;
            }
            else if (Core.Network.Local.Equals(message))
            {
                MessageTextBox.SelectionColor = message.Sent ? Color.Red : Color.LightCoral;
            }
            else
            {
                MessageTextBox.SelectionColor = Color.Blue;
            }

            MessageTextBox.SelectionFont = BoldFont;

            string prefix = " ";

            if (!message.System)
            {
                prefix += Chat.GetNameAndLocation(message);
            }

            if (MessageTextBox.Text.Length != 0)
            {
                prefix = "\n" + prefix;
            }


            // add timestamp
            if (TimestampMenu.Checked)
            {
                MessageTextBox.AppendText(prefix);

                MessageTextBox.SelectionFont = TimeFont;
                MessageTextBox.AppendText(" (" + message.TimeStamp.ToString("T") + ")");

                MessageTextBox.SelectionFont = BoldFont;
                prefix = "";
            }

            if (!message.System)
            {
                prefix += ": ";
            }

            MessageTextBox.AppendText(prefix);

            // message, grey for not acked
            MessageTextBox.SelectionColor = Color.Black;
            if (Core.Network.Local.Equals(message) && !message.Sent)
            {
                MessageTextBox.SelectionColor = Color.LightGray;
            }

            if (message.System)
            {
                MessageTextBox.SelectionFont = SystemFont;
                MessageTextBox.AppendText(" *" + message.Text);
            }
            else
            {
                MessageTextBox.SelectionFont = RegularFont;

                if (message.Format == TextFormat.RTF)
                {
                    MessageTextBox.SelectedRtf = GuiUtils.RtftoColor(message.Text, MessageTextBox.SelectionColor);
                }
                else
                {
                    MessageTextBox.AppendText(message.Text);
                }
            }


            MessageTextBox.SelectionStart  = oldStart;
            MessageTextBox.SelectionLength = oldLength;

            MessageTextBox.DetectLinksDefault();

            if (!MessageTextBox.Focused)
            {
                MessageTextBox.SelectionStart = MessageTextBox.Text.Length;
                MessageTextBox.ScrollToCaret();
            }

            ParentView.MessageFlash();
        }
Example #2
0
        public void IM_MessageUpdate(ulong id, InstantMessage message)
        {
            if (id != UserID)
            {
                return;
            }

            int oldStart  = MessageTextBox.SelectionStart;
            int oldLength = MessageTextBox.SelectionLength;

            MessageTextBox.SelectionStart  = MessageTextBox.Text.Length;
            MessageTextBox.SelectionLength = 0;

            // name, in bold, blue for incoming, red for outgoing
            if (message.System)
            {
                MessageTextBox.SelectionColor = Color.Black;
            }
            else if (Core.Network.Local.Equals(message))
            {
                MessageTextBox.SelectionColor = message.Sent ? Color.Red : Color.LightCoral;
            }
            else
            {
                MessageTextBox.SelectionColor = Color.Blue;
            }

            MessageTextBox.SelectionFont = BoldFont;

            string prefix = " ";

            if (!message.System)
            {
                prefix += Core.GetName(message.UserID);
            }

            if (MessageTextBox.Text.Length != 0)
            {
                prefix = "\n" + prefix;
            }

            // add timestamp
            if (TimestampMenu.Checked)
            {
                MessageTextBox.AppendText(prefix);

                MessageTextBox.SelectionFont = TimeFont;
                MessageTextBox.AppendText(" (" + message.TimeStamp.ToString("T") + ")");

                MessageTextBox.SelectionFont = BoldFont;
                prefix = "";
            }

            string location = "";

            if (!message.System && Locations.ActiveClientCount(message.UserID) > 1)
            {
                location = " @" + Locations.GetLocationName(message.UserID, message.ClientID);
            }


            if (!message.System)
            {
                prefix += location + ": ";
            }

            MessageTextBox.AppendText(prefix);

            // message, grey for not acked
            MessageTextBox.SelectionColor = Color.Black;
            if (Core.Network.Local.Equals(message) && !message.Sent)
            {
                MessageTextBox.SelectionColor = Color.LightGray;
            }

            if (message.System)
            {
                MessageTextBox.SelectionFont = SystemFont;
                MessageTextBox.AppendText(" *" + message.Text);
            }
            else
            {
                MessageTextBox.SelectionFont = RegularFont;

                if (message.Format == TextFormat.RTF)
                {
                    MessageTextBox.SelectedRtf = GuiUtils.RtftoColor(message.Text, MessageTextBox.SelectionColor);
                }

                else if (message.Format == TextFormat.Plain)
                {
                    MessageTextBox.AppendText(message.Text);
                }
            }


            MessageTextBox.SelectionStart  = oldStart;
            MessageTextBox.SelectionLength = oldLength;

            MessageTextBox.DetectLinksDefault();

            if (!MessageTextBox.Focused)
            {
                MessageTextBox.SelectionStart = MessageTextBox.Text.Length;
                MessageTextBox.ScrollToCaret();
            }

            if (External != null && !WindowActivated)
            {
                FlashMe = true;
            }
        }