Example #1
0
        /// <summary>
        /// Renders the specified chat node to the client.
        /// </summary>
        /// <param name="node">The node to append.</param>
        /// <remarks>
        /// <para>The return value of this function is a reference to the outermost <see cref="HtmlElement">HtmlElement</see> constructed
        /// by this function.  It may create additional inner elements as needed.</para>
        /// </remarks>
        /// <returns>
        /// Returns an object instance of <see cref="HtmlElement">HtmlElement</see> that can be appended to the HTML document.
        /// </returns>
        public override Inline Render(ChatNode node)
        {
            IIconProvider provider = ProfileResourceProvider.GetForClient(null).Icons;

            ImageChatNode icn = node as ImageChatNode;
            if (icn != null)
            {
                InlineUIContainer result = new InlineUIContainer();
                Image img = new Image();
                img.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap((icn.Image as System.Drawing.Bitmap).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                img.ToolTip = icn.Text;
                img.Width = provider.IconSize.Width;
                img.Height = provider.IconSize.Height;

                result.Child = img;

                if (icn.LinkUri != null)
                {
                    Hyperlink container = new Hyperlink(result);
                    container.NavigateUri = node.LinkUri;
                    container.ToolTip = string.Format(CultureInfo.CurrentUICulture, "Link to {0}", node.LinkUri);

                    return container;
                }

                return result;
            }
            else
            {
                return base.Render(node);
            }
        }
Example #2
0
        private Inline RenderNode(ChatNode node)
        {
            if (!m_renderers.ContainsKey(node.GetType()))
            {
                Type rendererType = ChatNodeRendererAttribute.RetrieveFromType(node.GetType());
                InitializeRenderer(node.GetType(), rendererType);
            }

            return(m_renderers[node.GetType()].Render(node));
        }
Example #3
0
        /// <summary>
        /// Renders the specified chat node to the client.
        /// </summary>
        /// <param name="node">The node to append.</param>
        /// <remarks>
        /// <para>The return value of this function is a reference to the outermost <see cref="Inline">Inline</see> constructed
        /// by this function.  It may create additional inner elements as needed.</para>
        /// </remarks>
        /// <returns>
        /// Returns an object instance of <see cref="Inline">Inline</see> that can be appended to the HTML document.
        /// </returns>
        public virtual Inline Render(ChatNode node)
        {
            Inline result;

            if (node == ChatNode.NewLine)
            {
                result = new LineBreak();
            }
            else if (node.LinkUri == null)
            {
                Run run = new Run();
                if (node.CssClass != null)
                {
                    run.Style = ResourceProvider[node.CssClass] as Style;
                    run.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass);
                }
                else if (node.Color != GdiColor.Empty)
                {
                    run.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, node.Color.R, node.Color.G, node.Color.B));
                }
                run.Text = node.Text;

                result = run;
            }
            else // need to make a link.
            {
                Hyperlink link = new Hyperlink();
                link.Inlines.Add(new Run(node.Text));
                link.NavigateUri = node.LinkUri;

                if (node.CssClass != null)
                {
                    link.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass);
                }
                else if (node.Color != GdiColor.Empty)
                {
                    link.Foreground = new SolidColorBrush(WpfColor.FromArgb(255, node.Color.R, node.Color.G, node.Color.B));
                }

                link.ToolTip = string.Format(CultureInfo.CurrentUICulture, "Link to {0}", node.LinkUri.ToString());

                result = link;
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// Renders the specified chat node to the client.
        /// </summary>
        /// <param name="node">The node to append.</param>
        /// <remarks>
        /// <para>The return value of this function is a reference to the outermost <see cref="Inline">Inline</see> constructed
        /// by this function.  It may create additional inner elements as needed.</para>
        /// </remarks>
        /// <returns>
        /// Returns an object instance of <see cref="Inline">Inline</see> that can be appended to the HTML document.
        /// </returns>
        public virtual Inline Render(ChatNode node)
        {
            Inline result;

            if (node == ChatNode.NewLine)
            {
                result = new LineBreak();
            } 
            else if (node.LinkUri == null)
            {
                Run run = new Run();
                if (node.CssClass != null)
                {
                    run.Style = ResourceProvider[node.CssClass] as Style;
                    run.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass);
                }
                else if (node.Color != GdiColor.Empty)
                {
                    run.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, node.Color.R, node.Color.G, node.Color.B));
                }
                run.Text = node.Text;

                result = run;
            }
            else // need to make a link.
            {
                Hyperlink link = new Hyperlink();
                link.Inlines.Add(new Run(node.Text));
                link.NavigateUri = node.LinkUri;

                if (node.CssClass != null)
                {
                    link.SetResourceReference(FrameworkContentElement.StyleProperty, node.CssClass);
                }
                else if (node.Color != GdiColor.Empty)
                {
                    link.Foreground = new SolidColorBrush(WpfColor.FromArgb(255, node.Color.R, node.Color.G, node.Color.B));
                }

                link.ToolTip = string.Format(CultureInfo.CurrentUICulture, "Link to {0}", node.LinkUri.ToString());

                result = link;
            }

            return result;
        }
Example #5
0
        // Actually adds the nodes to the chat window.
        private void AddChatImpl(List <ChatNode> nodes)
        {
            if (IncludeTimestamp)
            {
                DateTime now       = DateTime.Now;
                string   timestamp = string.Format(CultureInfo.CurrentCulture, m_timestampFormat, now.Hour, now.Minute, now.Second);
                ChatNode ts        = new ChatNode(timestamp, m_tsColor);
                nodes.InsertRange(0, new ChatNode[] { ts, new ChatNode(" ", Color.Black) });
            }

            Paragraph   element = ParseChatNodesIntoParagraph(nodes.ToArray());
            ThreadStart invokee = delegate
            {
                display.Document.Blocks.Add(element);
                if (display.Viewer.Selection.IsEmpty)
                {
                    display.Viewer.FindFirstVisualDescendantOfType <ScrollViewer>().ScrollToBottom();
                }
            };

            display.Dispatcher.BeginInvoke(invokee);

            UpdateParagraphs();
        }
Example #6
0
 /// <summary>
 /// Adds chat nodes to the display in a single line.
 /// </summary>
 /// <param name="node1">The first node to add.</param>
 /// <param name="node2">The second node to add.</param>
 /// <param name="node3">The third node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node1, ChatNode node2, ChatNode node3)
 {
     AddChatPrivate(new List<ChatNode> { node1, node2, node3 });
 }
Example #7
0
 /// <summary>
 /// Adds a chat node to the display.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node)
 {
     AddChatPrivate(new List<ChatNode> { node });
 }
Example #8
0
        private Inline RenderNode(ChatNode node)
        {
            if (!m_renderers.ContainsKey(node.GetType()))
            {
                Type rendererType = ChatNodeRendererAttribute.RetrieveFromType(node.GetType());
                InitializeRenderer(node.GetType(), rendererType);
            }

            return m_renderers[node.GetType()].Render(node);
        }
Example #9
0
 /// <summary>
 /// Adds a chat node to the display.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node)
 {
     display.AddChat(node);
 }
Example #10
0
 /// <summary>
 /// Adds chat nodes to the display in a single line.
 /// </summary>
 /// <param name="node1">The first node to add.</param>
 /// <param name="node2">The second node to add.</param>
 /// <param name="node3">The third node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node1, ChatNode node2, ChatNode node3)
 {
     AddChatPrivate(new List <ChatNode> {
         node1, node2, node3
     });
 }
Example #11
0
 /// <summary>
 /// Copies the specified <b>ChatNode</b> object.
 /// </summary>
 /// <param name="source">The source ChatNode to copy.</param>
 /// <remarks>
 /// <para>This overload is provided for use when marshaling messages across AppDomain boundaries
 /// and when the specified system message will be used to render GUI elements.</para>
 /// </remarks>
 public ChatNode(ChatNode source)
 {
     this.m_col = source.Color;
     this.m_text = source.Text;
     this.m_uri = source.LinkUri;
 }
Example #12
0
 /// <summary>
 /// Adds chat nodes to the display in a single line.
 /// </summary>
 /// <param name="node1">The first node to add.</param>
 /// <param name="node2">The second node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node1, ChatNode node2)
 {
     display.AddChat(node1, node2);
 }
Example #13
0
 /// <summary>
 /// Adds a chat node to the display.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node)
 {
     display.AddChat(node);
 }
Example #14
0
        internal void addChat(ArrayInstance chatNodes)
        {
            List<ChatNode> result = new List<ChatNode>();

            for (int i = 0; i < chatNodes.Length; i++)
            {
                ObjectInstance obj = chatNodes[i] as ObjectInstance;
                if (obj == null)
                    continue;

                string str = obj.GetPropertyValue("text") as string;
                object oTxt = obj.GetPropertyValue("text");
                if (oTxt == null) continue;
                str = oTxt.ToString();

                ColorInstance color = obj.GetPropertyValue("color") as ColorInstance;
                string cssClass = obj.GetPropertyValue("cssClass") as string;

                if (str == null)
                    continue;
                else if (color == null && cssClass == null)
                    continue;

                ChatNode node;
                if (color == null)
                {
                    node = new ChatNode(str, cssClass);
                }
                else
                {
                    node = new ChatNode(str, Color.FromArgb(255, color.R, color.G, color.B));
                }

                result.Add(node);
            }

            try
            {
                _client.MainWindow.AddChat(result);
            }
            catch (Exception ex)
            {
                throw new JavaScriptException(_engine, ex.GetType().Name, ex.Message);
            }
        }
Example #15
0
 /// <summary>
 /// Adds chat nodes to the display in a single line.
 /// </summary>
 /// <param name="node1">The first node to add.</param>
 /// <param name="node2">The second node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node1, ChatNode node2)
 {
     display.AddChat(node1, node2);
 }
Example #16
0
 /// <summary>
 /// Adds a chat node to the display.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <exception cref="ArgumentNullException">Thrown if a node is <b>null</b> (<b>Nothing</b> in Visual Basic).</exception>
 public void AddChat(ChatNode node)
 {
     AddChatPrivate(new List <ChatNode> {
         node
     });
 }
Example #17
0
        // Actually adds the nodes to the chat window.
        private void AddChatImpl(List<ChatNode> nodes)
        {
            if (IncludeTimestamp)
            {
                DateTime now = DateTime.Now;
                string timestamp = string.Format(CultureInfo.CurrentCulture, m_timestampFormat, now.Hour, now.Minute, now.Second);
                ChatNode ts = new ChatNode(timestamp, m_tsColor);
                nodes.InsertRange(0, new ChatNode[] { ts, new ChatNode(" ", Color.Black) });
            }

            Paragraph element = ParseChatNodesIntoParagraph(nodes.ToArray());
            ThreadStart invokee = delegate
            {
                display.Document.Blocks.Add(element);
                if (display.Viewer.Selection.IsEmpty) 
                    display.Viewer.FindFirstVisualDescendantOfType<ScrollViewer>().ScrollToBottom();
            };
            display.Dispatcher.BeginInvoke(invokee);

            UpdateParagraphs();
        }
Example #18
0
        private Paragraph ParseChatNodesIntoParagraph(ChatNode[] nodes)
        {
            Paragraph fullElement = new Paragraph();
            foreach (ChatNode node in nodes)
            {
                Inline child = RenderNode(node);
                fullElement.Inlines.Add(child);
            }

            fullElement.Style = display.Resources["Paragraphs"] as Style;
            fullElement.SetResourceReference(FrameworkContentElement.StyleProperty, "Paragraphs");

            return fullElement;
        }
Example #19
0
 /// <summary>
 /// Copies the specified <b>ChatNode</b> object.
 /// </summary>
 /// <param name="source">The source ChatNode to copy.</param>
 /// <remarks>
 /// <para>This overload is provided for use when marshaling messages across AppDomain boundaries
 /// and when the specified system message will be used to render GUI elements.</para>
 /// </remarks>
 public ChatNode(ChatNode source)
 {
     this.m_col  = source.Color;
     this.m_text = source.Text;
     this.m_uri  = source.LinkUri;
 }