/// <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; }
private Client.RichTBox.Line CreateLine(ContentLine Line) { Color color = Configuration.CurrentSkin.FontColor; switch (Line.style) { case Client.ContentLine.MessageStyle.Action: color = Configuration.CurrentSkin.MiscelancsColor; break; case Client.ContentLine.MessageStyle.Kick: color = Configuration.CurrentSkin.KickColor; break; case Client.ContentLine.MessageStyle.System: color = Configuration.CurrentSkin.MiscelancsColor; break; case Client.ContentLine.MessageStyle.Channel: color = Configuration.CurrentSkin.ColorTalk; break; case Client.ContentLine.MessageStyle.User: color = Configuration.CurrentSkin.changenickcolor; break; case Client.ContentLine.MessageStyle.Join: case Client.ContentLine.MessageStyle.Part: color = Configuration.CurrentSkin.JoinColor; break; } if (Line.notice) { color = Configuration.CurrentSkin.HighlightColor; } string stamp = ""; if (Configuration.Scrollback.chat_timestamp) { stamp = Configuration.Scrollback.format_date.Replace("$1", Line.time.ToString(Configuration.Scrollback.timestamp_mask)); } Client.RichTBox.Line text = Parser.FormatLine(Line.text, RT, color); Client.RichTBox.ContentText content = new Client.RichTBox.ContentText(stamp, color); Client.RichTBox.Line line = new Client.RichTBox.Line(RT); line.insertData(content); line.Merge(text); return line; }