* Corrected small things to make Circ-git compile from within MonoDevelop
[circ.git] / Circ.Frontend.GtkSharp / MessagesPanel.cs
blobc17f73ea17e8dcbee90eee4ca6570c86358b0849
1 #region License
2 /* Circ.Frontend.GtkSharp : GTK# frontend for Circ
3 * Copyright (C) 2007 LAVAL Jérémie
5 * This file is licensed under the terms of the LGPL.
7 * For the complete licence see the file COPYING.
8 */
9 #endregion
10 using System;
11 using Circ.Lib;
12 using Gtk;
13 using Gdk;
15 namespace Circ.Frontend.GtkSharp
18 public class MessagesPanel: TextView
20 static TextTagTable txtTags;
21 TextBuffer buffer;
22 TextMark endMark;
24 Gdk.Color background;
26 public MessagesPanel(): base()
28 this.Editable = false;
29 //this.DoubleBuffered = true;
30 this.WrapMode = Gtk.WrapMode.Word;
31 this.CursorVisible = false;
32 this.LeftMargin = 3;
33 this.RightMargin = 3;
34 this.CanFocus = false;
36 background = new Gdk.Color ();
37 Gdk.Color.Parse (Options.GetStringConfig("background"), ref background);
38 this.ModifyBg (StateType.Normal, background);
39 this.ModifyBase (StateType.Normal, background);
41 RgbColor textColor = LibContrast.GetBestColorFromBackground(new RgbColor((byte)(background.Red/257),
42 (byte)(background.Green/257), (byte)(background.Blue/257)), ColorPalette.Aqua);
43 this.ModifyText(StateType.Normal, new Gdk.Color(textColor.Red, textColor.Green, textColor.Blue));
44 this.ModifyFont(Pango.FontDescription.FromString(Options.GetStringConfig("font")));
46 if (txtTags == null)
47 InitTextTags();
49 this.buffer = new TextBuffer(txtTags);
50 this.Buffer = buffer;
51 this.endMark = buffer.CreateMark("end", buffer.EndIter, false);
52 //this.buffer.InsertText += InsertionHandler;
55 private void InitTextTags()
57 txtTags = new TextTagTable();
58 RgbColor backgroundColor = new RgbColor((byte)(background.Red/257), (byte)(background.Green/257), (byte)(background.Blue/257));
60 // Instanciation
61 TextTag message = new TextTag("message");
62 TextTag author = new TextTag("author");
63 TextTag hl = new TextTag("hl");
64 TextTag itsme = new TextTag("itsme");
65 TextTag notice = new TextTag("notice");
66 TextTag time = new TextTag("time");
69 // Tuning (follow Tango color scheme)
70 RgbColor hlColor = LibContrast.GetBestColorFromBackground(backgroundColor, (ColorPalette)ColorPalette.Parse(typeof(ColorPalette), Options.GetStringConfig("hl")));
71 hl.ForegroundGdk = new Gdk.Color(hlColor.Red, hlColor.Green, hlColor.Blue);
72 hl.PixelsBelowLines = 3;
74 RgbColor messageColor = LibContrast.GetBestColorFromBackground(backgroundColor, (ColorPalette)Enum.Parse(typeof(ColorPalette), Options.GetStringConfig("author")));
75 message.ForegroundGdk = new Color(messageColor.Red, messageColor.Green, messageColor.Blue);
76 message.PixelsBelowLines = 2;
78 // This Enum.Parse() method is really really crappy
79 RgbColor authorColor = LibContrast.GetBestColorFromBackground(backgroundColor, (ColorPalette)Enum.Parse(typeof(ColorPalette), Options.GetStringConfig("author")));
80 author.ForegroundGdk = new Color(authorColor.Red, authorColor.Green, authorColor.Blue);
81 author.Weight = Pango.Weight.Bold;
83 RgbColor meColor = LibContrast.GetBestColorFromBackground(backgroundColor, (ColorPalette)ColorPalette.Parse(typeof(ColorPalette), Options.GetStringConfig("self")));
84 itsme.ForegroundGdk = new Color(meColor.Red, meColor.Green, meColor.Blue);
86 RgbColor tiColor = LibContrast.GetBestColorFromBackground(backgroundColor, (ColorPalette)ColorPalette.Parse(typeof(ColorPalette), Options.GetStringConfig("date")));
87 time.ForegroundGdk = new Color(tiColor.Red, tiColor.Green, tiColor.Blue);
89 RgbColor noticeColor = LibContrast.GetBestColorFromBackground(backgroundColor, (ColorPalette)ColorPalette.Parse(typeof(ColorPalette), Options.GetStringConfig("notice")));
90 notice.ForegroundGdk = new Color(noticeColor.Red, noticeColor.Green, noticeColor.Blue);
92 txtTags.Add(message);
93 txtTags.Add(author);
94 txtTags.Add(hl);
95 txtTags.Add(notice);
96 txtTags.Add(time);
97 txtTags.Add(itsme);
100 internal void ScrollToEnd()
102 this.ScrollMarkOnscreen(endMark);