예제 #1
0
        private void addChatMessage(WappMessage message)
        {
            ListChat lc = new ListChat(message);

            this.flowLayoutPanel1.Controls.Add(lc);
            while (this.flowLayoutPanel1.Controls.Count > MESSAGE_LIMIT)
            {
                this.flowLayoutPanel1.Controls.Remove(this.flowLayoutPanel1.Controls[0]);
            }
        }
예제 #2
0
        public ListChat(WappMessage msg, MetroFramework.MetroColorStyle style)
        {
            InitializeComponent();
            this.Style                = style;
            this.metroTile1.Style     = style;
            this.metroTile1.BackColor = Helper.GetMetroThemeColor(style);
            if (msg.from_me)
            {
                this.Padding = new Padding(50, this.Padding.Top, 4, this.Padding.Bottom);
            }
            if (!String.IsNullOrEmpty(msg.author))
            {
                Contact c = ContactStore.GetContactByJid(msg.author);
                if (c != null)
                {
                    msg.author = c.FullName;
                }
                msg.data = String.Format("{0}\r\n{1}", msg.author, msg.data);
            }
            if (msg.type == "image")
            {
                if (!string.IsNullOrEmpty(msg.preview))
                {
                    MemoryStream ms = new MemoryStream(Convert.FromBase64String(msg.preview));
                    Image        i  = Image.FromStream(ms);
                    this.Height += i.Height;
                    this.Controls.Remove(this.metroTile1);
                    PictureBox pb = new PictureBox();
                    pb.Width  = i.Width;
                    pb.Height = i.Height;
                    pb.Image  = i;
                    this.Controls.Add(pb);
                }
            }
            else
            {
                Font  f          = MetroFonts.Tile(this.metroTile1.TileTextFontSize, this.metroTile1.TileTextFontWeight);
                int   lineHeight = Int32.Parse(Math.Round((decimal)this.metroTile1.CreateGraphics().MeasureString("X", f).Height).ToString());
                SizeF sf         = new SizeF();
                sf = this.metroTile1.CreateGraphics().MeasureString(msg.data, f, this.metroTile1.Width);
                this.metroTile1.Text = msg.data;
                int newHeight = (int)Math.Round(decimal.Parse(sf.Height.ToString()));
                int lines     = newHeight / f.Height;
                //lines--;

                if (lines > 0)
                {
                    this.Height = (lines * this.Height);
                }
            }
        }
예제 #3
0
 public void AddMessage(string from, string data, bool fromMe)
 {
     if (this.flowLayoutPanel1.InvokeRequired)
     {
         AddMessageCustomCallback call = new AddMessageCustomCallback(AddMessage);
         this.Invoke(call, new object[] { from, data, fromMe });
     }
     else
     {
         WappMessage msg = new WappMessage(from, data, fromMe);
         this.messages.Add(msg);
         this.limitMessages();
         MessageStore.AddMessage(msg);
         this.addChatMessage(msg);
         this.ScrollToBottom();
     }
 }
예제 #4
0
 public void AddMessage(string message)
 {
     if (this.flowLayoutPanel1.InvokeRequired)
     {
         AddMessageCallback r = new AddMessageCallback(AddMessage);
         this.Invoke(r, new object[] { message });
     }
     else
     {
         WappMessage msg = new WappMessage(message, this.target);
         this.messages.Add(msg);
         this.limitMessages();
         MessageStore.AddMessage(msg);
         this.addChatMessage(msg);
         this.ScrollToBottom();
     }
 }
예제 #5
0
 public ListChat(WappMessage msg)
 {
     InitializeComponent();
     this.textBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;
     if (!msg.from_me)
     {
         this.textBox1.Location = new Point(3, this.textBox1.Location.Y);
     }
     if (!String.IsNullOrEmpty(msg.author))
     {
         Contact c = ContactStore.GetContactByJid(msg.author);
         if (c != null)
         {
             msg.author = c.FullName;
         }
         msg.data = String.Format("{0}\r\n{1}", msg.author, msg.data);
     }
     if (msg.type == "image")
     {
         if (!string.IsNullOrEmpty(msg.preview))
         {
             MemoryStream ms = new MemoryStream(Convert.FromBase64String(msg.preview));
             Image        i  = Image.FromStream(ms);
             this.Height += i.Height;
             this.Controls.Remove(this.textBox1);
             PictureBox pb = new PictureBox();
             pb.Width  = i.Width;
             pb.Height = i.Height;
             pb.Image  = i;
             this.Controls.Add(pb);
         }
     }
     else
     {
         this.textBox1.Text = msg.data;
         Size size = TextRenderer.MeasureText(this.textBox1.Text, this.textBox1.Font, new Size(this.textBox1.Width, int.MaxValue), TextFormatFlags.WordBreak);
         this.Height = size.Height + 15;
     }
 }
예제 #6
0
 public void AddMessage(ProtocolTreeNode node)
 {
     if (this.flowLayoutPanel1.InvokeRequired)
     {
         AddMessageCallbackNode r = new AddMessageCallbackNode(AddMessage);
         this.Invoke(r, new object[] { node });
     }
     else
     {
         string      author = String.Empty;
         WappMessage msg    = new WappMessage(node, this.target);
         if (this.IsGroup)
         {
             //extract author
             msg.author = node.GetAttribute("author");
         }
         this.messages.Add(msg);
         this.limitMessages();
         MessageStore.AddMessage(msg);
         this.addChatMessage(msg);
         this.ScrollToBottom();
     }
 }