Пример #1
0
 private void CreateLine(string Text, RichTBox SBAB, Color color)
 {
     text.Add(new ContentText(Text, SBAB.ForeColor));
     foreColor = SBAB.foreColor;
 }
Пример #2
0
        /// <summary>
        /// Format line, this function is used to format text so that it has colors, clickable URL's and so
        /// </summary>
        /// <param name="text">Text that needs to be formatted</param>
        /// <param name="SBAB">This is object which replaced former SBA control, it is now a RichTBox,
        /// which is a custom widget for GTK used only by pidgeon with same interface as SBA had</param>
        /// <param name="_style">Default color for this text</param>
        /// <returns></returns>
        public static Client.RichTBox.Line FormatLine(string text, RichTBox SBAB, Color _style)
        {
            if (SBAB == null)
            {
                throw new Core.PidgeonException("NULL reference to RichTBox object");
            }

            Client.RichTBox.Line line = null;

            if (CacheEnabled)
            {
                line = FromCache(text);
                if (line != null)
                {
                    return line;
                }
            }

            line = new Client.RichTBox.Line("", SBAB);
            Client.RichTBox.ContentText lprttext = null;
            string tempdata = text;
            Color color = _style;
            string templine = "";
            bool Bold = false;
            bool Underlined = false;
            bool Italic = false;
            string Link = null;
            int Jump = 0;

            int carret = 0;

            while (carret < text.Length)
            {
                Jump = 1;
                // we check if the current string is actually some url
                string protocol = matchesProtocol(tempdata);
                if (protocol != null)
                {
                    // check if there is a prefix character that is a symbol which separates the url
                    char prefix = Prefix(tempdata, protocol);
                    if (!string.IsNullOrEmpty(templine) || prefix != '\0')
                    {
                        // if there is a text in buffer from previous call, we need to build it
                        if (prefix != '\0')
                        {
                            // we append the prefix to previous text because it must not be a part of url
                            lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine) + prefix.ToString(), color);
                        }
                        else
                        {
                            // there was no prefix
                            lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                        }
                        lprttext.Underline = Underlined;
                        lprttext.Bold = Bold;
                        lprttext.TextColor = color;
                        lprttext.Italic = Italic;
                        if (Link != null)
                        {
                            lprttext.Link = Link;
                        }
                        line.insertData(lprttext);
                        templine = "";
                    }
                    if (prefix != '\0')
                    {
                        // now we need to create a hyperlink, we parse it using the prefix
                        line.insertData(parse_http(tempdata, SBAB, Underlined, Bold, color, protocol, prefix.ToString()));
                    }
                    else
                    {
                        // create a hyperlink not using the prefix
                        line.insertData(parse_http(tempdata, SBAB, Underlined, Bold, color, protocol));
                    }
                    string temp01 = tempdata.Substring(1);
                    // we check if there is another separator in the rest of link
                    if (matchesAPrefix(temp01))
                    {
                        Jump = temp01.IndexOf(Prefix(temp01)) + 1;
                    }
                    else
                    {
                        Jump = tempdata.Length;
                    }
                }
                else if (tempdata.StartsWith("%USER%", StringComparison.Ordinal))
                {
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Underline = Underlined;
                    lprttext.Italic = Italic;
                    line.insertData(lprttext);
                    templine = "";
                    line.insertData(parse_name(tempdata, SBAB, Underlined, Bold, color));
                    if (tempdata.Contains("%/USER%"))
                    {
                        Jump = tempdata.IndexOf("%/USER%", StringComparison.Ordinal) + 7;
                    }
                    else
                    {
                        Jump = tempdata.Length - 1;
                    }
                }
                else if (tempdata.StartsWith(" #", StringComparison.Ordinal)
                    || (tempdata.StartsWith("#", StringComparison.Ordinal) && text.StartsWith("#", StringComparison.Ordinal)))
                {
                    if (tempdata.StartsWith(" #", StringComparison.Ordinal))
                    {
                        templine += text[carret].ToString();
                        carret++;
                        tempdata = tempdata.Substring(1);
                    }

                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Underline = Underlined;
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    line.insertData(lprttext);
                    templine = "";

                    line.insertData(parse_chan(tempdata, SBAB, Underlined, Bold, color));
                    if (tempdata.Contains(" "))
                    {
                        Jump = tempdata.IndexOf(" ", StringComparison.Ordinal);
                    }
                    else
                    {
                        Jump = tempdata.Length;
                    }
                }
                else if (tempdata.StartsWith(((char)0016).ToString(), StringComparison.Ordinal))
                {
                    tempdata = tempdata.Substring(1);
                    Jump = 0;
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    Italic = !Italic;
                    carret++;
                }
                else if (tempdata.StartsWith(((char)001).ToString(), StringComparison.Ordinal))
                {
                    tempdata = tempdata.Substring(1);
                    Jump = 0;
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    Underlined = !Underlined;
                    carret++;
                }
                else if (tempdata.StartsWith(((char)002).ToString(), StringComparison.Ordinal))
                {
                    tempdata = tempdata.Substring(1);
                    Jump = 0;
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    Bold = !Bold;
                    carret++;
                }
                else if (tempdata.StartsWith(((char)003).ToString(), StringComparison.Ordinal))
                {
                    // change color
                    int colorcode = -2;
                    tempdata = tempdata.Substring(1);
                    carret++;
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    if (tempdata.Length > 1)
                    {
                        if (!int.TryParse(tempdata.Substring(0, 2), out colorcode))
                        {
                            if (!int.TryParse(tempdata.Substring(0, 1), out colorcode))
                            {
                                // we just terminated the color
                                color = _style;
                                colorcode = -2;
                            }
                            else
                            {
                                tempdata = tempdata.Substring(1);
                                carret++;
                            }
                        }
                        else
                        {
                            tempdata = tempdata.Substring(2);
                            carret++;
                            carret++;
                        }
                    }
                    Jump = 0;
                    templine = "";
                    if (colorcode >= 0)
                    {
                        if (colorcode < 16)
                        {
                            color = Configuration.CurrentSkin.mrcl[colorcode];
                        }
                        else
                        {
                            color = Configuration.CurrentSkin.mrcl[0];
                            Core.DebugLog("Invalid color for link: " + colorcode.ToString());
                        }
                    }
                }
                else if (tempdata.StartsWith(((char)004).ToString(), StringComparison.Ordinal))
                {
                    tempdata = tempdata.Substring(1);
                    Jump = 0;
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    Underlined = !Underlined;
                    carret++;
                }
                else if (tempdata.StartsWith("%H%", StringComparison.Ordinal))
                {
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    line.insertData(parse_host(tempdata, SBAB, Underlined, Bold, color));
                    if (tempdata.Contains("%/H%"))
                    {
                        Jump = tempdata.IndexOf("%/H%", StringComparison.Ordinal) + 4;
                    }
                    else
                    {
                        Jump = tempdata.Length;
                    }
                }
                else if (tempdata.StartsWith("%L%", StringComparison.Ordinal))
                {
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    line.insertData(parse_link(tempdata, SBAB, Underlined, Bold));
                    if (tempdata.Contains("%/L%"))
                    {
                        Jump = tempdata.IndexOf("%/L%", StringComparison.Ordinal) + 4;
                    }
                    else
                    {
                        Jump = tempdata.Length;
                    }
                }
                else if (tempdata.StartsWith("%D%", StringComparison.Ordinal))
                {
                    lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
                    lprttext.Bold = Bold;
                    lprttext.Italic = Italic;
                    lprttext.Underline = Underlined;
                    line.insertData(lprttext);
                    templine = "";
                    line.insertData(parse_ident(tempdata, SBAB, Underlined, Bold));
                    if (tempdata.Contains("%/D%"))
                    {
                        Jump = tempdata.IndexOf("%/D%", StringComparison.Ordinal) + 4;
                    }
                    else
                    {
                        Jump = tempdata.Length;
                    }
                }
                else
                {
                    templine += text[carret];
                }
                tempdata = tempdata.Substring(Jump);
                carret = carret + Jump;
            }
            lprttext = new Client.RichTBox.ContentText(ProtocolIrc.DecodeText(templine), color);
            lprttext.Underline = Underlined;
            lprttext.Italic = Italic;
            lprttext.Bold = Bold;
            line.insertData(lprttext);

            if (CacheEnabled)
            {
                ToCache(text, line);
            }

            return line;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Client.RichTBox.Line"/> class.
 /// </summary>
 /// <param name="SBAB">SBA.</param>
 public Line(RichTBox SBAB)
 {
     text = new List<ContentText>();
     foreColor = SBAB.foreColor;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Client.RichTBox.Line"/> class.
 /// </summary>
 /// <param name="Text">Text.</param>
 /// <param name="SBAB">SBA.</param>
 /// <param name="color">Color.</param>
 public Line(string Text, RichTBox SBAB, Color color)
 {
     CreateLine(Text, SBAB, color);
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Client.RichTBox.Line"/> class.
 /// </summary>
 /// <param name="Text">Text.</param>
 /// <param name="SBAB">SBA.</param>
 public Line(string Text, RichTBox SBAB)
 {
     if (SBAB == null)
     {
         throw new Core.PidgeonException("SBAB must not be null");
     }
     CreateLine(Text, SBAB, SBAB.ForeColor);
 }
Пример #6
0
 private void Build()
 {
     global::Stetic.Gui.Initialize(this);
     global::Stetic.BinContainer.Attach(this);
     this.Name = "Client.ScrollbackWidget";
     this.GtkScrolledWindow = new global::Gtk.ScrolledWindow();
     this.GtkScrolledWindow.Name = "GtkScrolledWindow";
     this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1));
     this.simpleview = new global::Gtk.TextView();
     this.simpleview.CanFocus = true;
     this.simpleview.WrapMode = Gtk.WrapMode.Word;
     this.Visible = true;
     this.simpleview.Name = "simpleview";
     this.simpleview.SizeAllocated += new Gtk.SizeAllocatedHandler(Scroll2);
     this.simpleview.Editable = false;
     this.simpleview.ModifyFont(Font);
     this.simpleview.ScrollEvent += new Gtk.ScrollEventHandler(Scroll);
     this.simpleview.DoubleBuffered = true;
     this.GtkScrolledWindow.Add(this.simpleview);
     this.RT = new RichTBox();
     if (!isMicro)
     {
         this.simpleview.PopulatePopup += new Gtk.PopulatePopupHandler(CreateMenu_simple);
         this.RT.textView.PopulatePopup += new Gtk.PopulatePopupHandler(CreateMenu_rt);
         this.RT.textView.ButtonPressEvent += new Gtk.ButtonPressEventHandler(Click);
         this.RT.textView.KeyPressEvent += new Gtk.KeyPressEventHandler(PressEvent);
     }
     timer2 = new GLib.TimeoutHandler(timer2_Tick);
     simpleview.ModifyBase(Gtk.StateType.Normal, Core.FromColor(Configuration.CurrentSkin.BackgroundColor));
     simpleview.ModifyText(Gtk.StateType.Normal, Core.FromColor(Configuration.CurrentSkin.ColorDefault));
     simpleview.KeyPressEvent += new Gtk.KeyPressEventHandler(PressEvent);
     GLib.Timeout.Add(200, timer2);
     this.Add(this.GtkScrolledWindow);
     if ((this.Child != null))
     {
         this.Child.ShowAll();
     }
 }
Пример #7
0
        /// <summary>
        /// Destroy this instance.
        /// </summary>
        public void _Destroy()
        {
            if (IsDestroyed)
            {
                return;
            }

            destroyed = true;
            lock (UndrawnLines)
            {
                UndrawnLines.Clear();
            }
            lock (ContentLines)
            {
                ContentLines.Clear();
            }
            simpleview.Destroy();
            RT = null;
            owner = null;
            this.Destroy();
        }