Beispiel #1
0
        public ChatView(ChatModel chat)
        {
            Trace.Call(chat);

            _ChatModel = chat;
            _Name = _ChatModel.Name;
            ID = _ChatModel.ID;
            Name = _Name;

            MessageTextView tv = new MessageTextView();
            _EndMark = tv.Buffer.CreateMark("end", tv.Buffer.EndIter, false);
            tv.ShowTimestamps = true;
            tv.ShowMarkerline = true;
            tv.Editable = false;
            tv.CursorVisible = true;
            tv.WrapMode = Gtk.WrapMode.Char;
            tv.MessageAdded += OnMessageTextViewMessageAdded;
            tv.MessageHighlighted += OnMessageTextViewMessageHighlighted;
            tv.PopulatePopup += OnMessageTextViewPopulatePopup;
            _OutputMessageTextView = tv;

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            //sw.HscrollbarPolicy = Gtk.PolicyType.Never;
            sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
            sw.VscrollbarPolicy = Gtk.PolicyType.Always;
            sw.ShadowType = Gtk.ShadowType.In;
            sw.Add(_OutputMessageTextView);
            _OutputScrolledWindow = sw;

            // popup menu
            _TabMenu = new Gtk.Menu();

            Gtk.ImageMenuItem close_item = new Gtk.ImageMenuItem(Gtk.Stock.Close, null);
            close_item.Activated += new EventHandler(OnTabMenuCloseActivated);
            _TabMenu.Append(close_item);

            //FocusChild = _OutputTextView;
            //CanFocus = false;

            _TabLabel = new Gtk.Label();
            _TabLabel.Text = _Name;

            _TabHBox = new Gtk.HBox();
            _TabHBox.PackEnd(new Gtk.Fixed(), true, true, 0);
            _TabHBox.PackEnd(_TabLabel, false, false, 0);
            _TabHBox.ShowAll();

            _TabEventBox = new Gtk.EventBox();
            _TabEventBox.VisibleWindow = false;
            _TabEventBox.ButtonPressEvent += new Gtk.ButtonPressEventHandler(OnTabButtonPress);
            _TabEventBox.Add(_TabHBox);
            _TabEventBox.ShowAll();

            _ThemeSettings = new ThemeSettings();

            // OPT-TODO: this should use a TaskStack instead of TaskQueue
            _LastSeenHighlightQueue = new TaskQueue("LastSeenHighlightQueue("+_Name+")");
            _LastSeenHighlightQueue.AbortedEvent += OnLastSeenHighlightQueueAbortedEvent;
            _LastSeenHighlightQueue.ExceptionEvent += OnLastSeenHighlightQueueExceptionEvent;
        }
Beispiel #2
0
        public XmppPersonChatView(PersonChatModel personChat) : base(personChat)
        {
            Trace.Call(personChat);

            OutputMessageTextView.PopulatePopup += _OnOutputMessageTextViewPopulatePopup;
            ChatStateStartPosition = new Gtk.TextMark("ChatStateStartPosition", true);
            IsDisposed             = false;
        }
Beispiel #3
0
        public TextTagEnumerator(Gtk.TextBuffer buffer, Gtk.TextTag tag)
        {
            this.buffer = buffer;
            this.tag    = tag;

            this.mark  = buffer.CreateMark(null, buffer.StartIter, true);
            this.range = new TextRange(buffer.StartIter, buffer.StartIter);
        }
Beispiel #4
0
        public XmppPersonChatView(PersonChatModel personChat)
            : base(personChat)
        {
            Trace.Call(personChat);

            OutputMessageTextView.PopulatePopup += _OnOutputMessageTextViewPopulatePopup;
            ChatStateStartPosition = new Gtk.TextMark("ChatStateStartPosition", true);
            IsDisposed = false;
        }
Beispiel #5
0
        void AddEmoji(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, ImageMessagePartModel imgPart, string shortName)
        {
            var unicode = Emojione.ShortnameToUnicode(shortName);

            if (unicode == null)
            {
                AddAlternativeText(buffer, ref iter, imgPart);
                return;
            }

            // A mark here serves two pusposes. One is to allow us to apply the
            // tag across the pixbuf. It also lets us know later where to put
            // the pixbuf if we need to load it from the network
            var mark = new Gtk.TextMark(null, true);

            buffer.AddMark(mark, iter);

            var    emojiName = unicode + ".png";
            string emojiPath;

            if (EmojiCache.TryGetIcon("emojione", emojiName, out emojiPath))
            {
                var emojiFile = new FileInfo(emojiPath);
                if (emojiFile.Exists && emojiFile.Length > 0)
                {
                    AddEmoji(buffer, ref iter, imgPart, shortName, mark, emojiPath);
                }
                else
                {
                    AddAlternativeText(buffer, ref iter, imgPart);
                }

                return;
            }

            var emojiUrl = Emojione.UnicodeToUrl(unicode);

            EmojiCache.BeginDownloadFile("emojione", emojiName, emojiUrl,
                                         (path) => {
                GLib.Idle.Add(delegate {
                    var markIter = buffer.GetIterAtMark(mark);
                    AddEmoji(buffer, ref markIter, imgPart, shortName, mark, path);
                    return(false);
                });
            },
                                         (ex) => {
                GLib.Idle.Add(delegate {
                    var markIter = buffer.GetIterAtMark(mark);
                    buffer.DeleteMark(mark);
                    AddAlternativeText(buffer, ref markIter, imgPart);
                    return(false);
                });
            }
                                         );
        }
Beispiel #6
0
        Gtk.TextIter DeleteLineAtMark(Gtk.TextMark mark)
        {
            var start = view.Buffer.GetIterAtMark(mark);
            var end   = view.Buffer.GetIterAtMark(mark);

            end.ForwardLine();

            view.Buffer.Delete(ref start, ref end);

            return(start);
        }
Beispiel #7
0
        public TextRange(Gtk.TextIter start,
                         Gtk.TextIter end)
        {
            if (start.Buffer != end.Buffer)
            {
                throw new Exception("Start buffer and end buffer do not match");
            }

            buffer     = start.Buffer;
            start_mark = buffer.CreateMark(null, start, true);
            end_mark   = buffer.CreateMark(null, end, true);
        }
        protected override void UpdateInputLineBegin()
        {
            if (tokenBeginMark == null)
            {
                tokenBeginMark = Buffer.CreateMark(null, Buffer.EndIter, true);
            }
            else
            {
                Buffer.MoveMark(tokenBeginMark, Buffer.EndIter);
            }

            base.UpdateInputLineBegin();
        }
Beispiel #9
0
        void PrintChildValueAtMark(ObjectValue val, Gtk.TextMark mark)
        {
            string prefix = "\t" + val.Name + ": ";
            string result = val.Value;

            if (string.IsNullOrEmpty(result) || val.IsError || val.IsUnknown || val.IsNotSupported)
            {
                SetLineText(prefix + GetErrorText(val), mark);
            }
            else
            {
                SetLineText(prefix + result, mark);
            }
        }
		public override void OnNoteOpened ()
		{
			Buffer.InsertText += OnInsertText;
			Buffer.DeleteRange += OnDeleteRange;
			Buffer.DeleteRange += OnDeleteRangeConnectBefore;
			Buffer.TagRemoved += OnTagRemoved;

			Window.Editor.ButtonPressEvent += OnButtonPress;
			Window.Editor.PopulatePopup += OnPopulatePopup;
			Window.Editor.PopupMenu += OnPopupMenu;

			click_mark = Buffer.CreateMark (null, Buffer.StartIter, true);

			UpdateTaskTagStatuses ();
		}
Beispiel #11
0
        public EmojiTag(Gtk.TextMark mark, string path) : base(null)
        {
            if (mark == null)
            {
                throw new ArgumentNullException("mark");
            }

            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            Mark = mark;
            Path = path;
        }
Beispiel #12
0
 private void InternalSourceMarkUpdated(Gtk.TextMark p0)
 {
     GLib.Value      ret             = GLib.Value.Empty;
     GLib.ValueArray inst_and_params = new GLib.ValueArray(2);
     GLib.Value[]    vals            = new GLib.Value [2];
     vals [0] = new GLib.Value(this);
     inst_and_params.Append(vals [0]);
     vals [1] = new GLib.Value(p0);
     inst_and_params.Append(vals [1]);
     g_signal_chain_from_overridden(inst_and_params.ArrayPtr, ref ret);
     foreach (GLib.Value v in vals)
     {
         v.Dispose();
     }
 }
Beispiel #13
0
        public override void OnNoteOpened()
        {
            Buffer.InsertText  += OnInsertText;
            Buffer.DeleteRange += OnDeleteRange;
            Buffer.DeleteRange += OnDeleteRangeConnectBefore;
            Buffer.TagRemoved  += OnTagRemoved;

            Window.Editor.ButtonPressEvent += OnButtonPress;
            Window.Editor.PopulatePopup    += OnPopulatePopup;
            Window.Editor.PopupMenu        += OnPopupMenu;

            click_mark = Buffer.CreateMark(null, Buffer.StartIter, true);

            UpdateTaskTagStatuses();
        }
Beispiel #14
0
        void AddEmoji(Gtk.TextBuffer buffer, ref Gtk.TextIter iter,
                      ImageMessagePartModel imgPart, string shortName,
                      Gtk.TextMark emojiMark, string imagePath)
        {
            int width, height;
            int descent;

            using (var layout = CreatePangoLayout(null)) {
                layout.GetPixelSize(out width, out height);
                descent = layout.Context.GetMetrics(layout.FontDescription, null).Descent;
            }

            Gdk.Pixbuf emojiPixBuf;
            try {
                emojiPixBuf = new Gdk.Pixbuf(imagePath, -1, height);
            } catch (Exception ex) {
#if LOG4NET
                _Logger.ErrorFormat(
                    "AddEmoji(): error loading " +
                    "image file: '{0}' " +
                    "emoji: '{1}' into Gdk.Pixbuf(), " +
                    "Exception: {2}",
                    imagePath, shortName, ex
                    );
#endif

                // delete the broken image file, maybe after the
                // next download this will be a valid image
                File.Delete(imagePath);

                // show alternative text as fallback instead
                buffer.DeleteMark(emojiMark);
                AddAlternativeText(buffer, ref iter, imgPart);
                return;
            }

            buffer.InsertPixbuf(ref iter, emojiPixBuf);
            var beforeIter = buffer.GetIterAtMark(emojiMark);
            var emojiTag   = new EmojiTag(emojiMark, imagePath)
            {
                Rise = -descent
            };
            _MessageTextTagTable.Add(emojiTag);
            buffer.ApplyTag(emojiTag, beforeIter, iter);
        }
Beispiel #15
0
        public override void OnNoteOpened()
        {
            // NOTE: This hack helps avoid multiple URL opens
            // now that Notes always perform
            // TagTable sharing.  This is because if the TagTable is
            // shared, we will connect to the same Tag's event
            // source each time a note is opened, and get called
            // multiple times for each button press.  Fixes bug
            // #305813.
            if (!text_event_connected)
            {
                Note.TagTable.UrlTag.Activated += OnUrlTagActivated;
                text_event_connected            = true;
            }

            click_mark = Buffer.CreateMark(null, Buffer.StartIter, true);

            Buffer.InsertText  += OnInsertText;
            Buffer.DeleteRange += OnDeleteRange;

            Window.Editor.ButtonPressEvent += OnButtonPress;
            Window.Editor.PopulatePopup    += OnPopulatePopup;
            Window.Editor.PopupMenu        += OnPopupMenu;
        }
Beispiel #16
0
        public ChatView(ChatModel chat)
        {
            Trace.Call(chat);

            _ChatModel = chat;

            IsAutoScrolling = true;
            MessageTextView tv = new MessageTextView();

            _EndMark               = tv.Buffer.CreateMark("end", tv.Buffer.EndIter, false);
            tv.ShowTimestamps      = true;
            tv.ShowMarkerline      = true;
            tv.Editable            = false;
            tv.CursorVisible       = true;
            tv.WrapMode            = Gtk.WrapMode.Char;
            tv.MessageAdded       += OnMessageTextViewMessageAdded;
            tv.MessageHighlighted += OnMessageTextViewMessageHighlighted;
            tv.PopulatePopup      += OnMessageTextViewPopulatePopup;
            tv.SizeRequested      += delegate {
                AutoScroll();
            };
            _OutputMessageTextView = tv;

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            _OutputScrolledWindow = sw;
            //sw.HscrollbarPolicy = Gtk.PolicyType.Never;
            sw.HscrollbarPolicy          = Gtk.PolicyType.Automatic;
            sw.VscrollbarPolicy          = Gtk.PolicyType.Always;
            sw.ShadowType                = Gtk.ShadowType.In;
            sw.Vadjustment.ValueChanged += delegate {
                CheckAutoScroll();
            };
            sw.Add(_OutputMessageTextView);

            // popup menu
            _TabMenu = new Gtk.Menu();

            Gtk.ImageMenuItem close_item = new Gtk.ImageMenuItem(Gtk.Stock.Close, null);
            close_item.Activated += new EventHandler(OnTabMenuCloseActivated);
            _TabMenu.Append(close_item);
            _TabMenu.ShowAll();

            //FocusChild = _OutputTextView;
            //CanFocus = false;

            _TabLabel = new Gtk.Label();

            TabImage = DefaultTabImage;
            _TabHBox = new Gtk.HBox();
            _TabHBox.PackEnd(new Gtk.Fixed(), true, true, 0);
            _TabHBox.PackEnd(_TabLabel, false, false, 0);
            _TabHBox.PackStart(TabImage, false, false, 2);
            _TabHBox.ShowAll();

            _TabEventBox = new Gtk.EventBox();
            _TabEventBox.VisibleWindow     = false;
            _TabEventBox.ButtonPressEvent += new Gtk.ButtonPressEventHandler(OnTabButtonPress);
            _TabEventBox.Add(_TabHBox);
            _TabEventBox.ShowAll();

            _ThemeSettings = new ThemeSettings();

            // OPT-TODO: this should use a TaskStack instead of TaskQueue
            _LastSeenHighlightQueue = new TaskQueue("LastSeenHighlightQueue(" + ID + ")");
            _LastSeenHighlightQueue.AbortedEvent   += OnLastSeenHighlightQueueAbortedEvent;
            _LastSeenHighlightQueue.ExceptionEvent += OnLastSeenHighlightQueueExceptionEvent;
        }
Beispiel #17
0
        void AddEmoji(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, ImageMessagePartModel imgPart, string shortName)
        {
            var unicode = Emojione.ShortnameToUnicode(shortName);
            if (unicode == null) {
                AddAlternativeText(buffer, ref iter, imgPart);
                return;
            }

            int width, height;
            int widthPango, heightPango;
            int descent;
            using (var layout = CreatePangoLayout(null)) {
                layout.GetPixelSize(out width, out height);
                layout.GetSize(out widthPango, out heightPango);
                descent = layout.Context.GetMetrics(layout.FontDescription, null).Descent;
            }

            // A mark here serves two pusposes. One is to allow us to apply the
            // tag across the pixbuf. It also lets us know later where to put
            // the pixbuf if we need to load it from the network
            var mark = new Gtk.TextMark(null, true);
            buffer.AddMark(mark, iter);

            var emojiName = unicode + ".png";
            string emojiPath;
            if (EmojiCache.TryGetIcon("emojione", emojiName, out emojiPath)) {
                var emojiFile = new FileInfo(emojiPath);
                if (emojiFile.Exists && emojiFile.Length > 0) {
                    var pix = new Gdk.Pixbuf(emojiPath, -1, height);
                    buffer.InsertPixbuf(ref iter, pix);
                    var beforeIter = buffer.GetIterAtMark(mark);
                    var imgTag = new EmojiTag(mark, emojiFile.FullName);
                    imgTag.Rise = - descent;
                    _MessageTextTagTable.Add(imgTag);
                    buffer.ApplyTag(imgTag, beforeIter, iter);
                } else {
                    AddAlternativeText(buffer, ref iter, imgPart);
                }

                return;
            }

            var emojiUrl = Emojione.UnicodeToUrl(unicode);
            EmojiCache.BeginDownloadFile("emojione", emojiName, emojiUrl,
                (path) => {
                    GLib.Idle.Add(delegate {
                        var afterIter = buffer.GetIterAtMark(mark);
                        buffer.InsertPixbuf(ref afterIter, new Gdk.Pixbuf(path, -1, height));
                        var beforeIter = buffer.GetIterAtMark(mark);
                        var emojiTag = new EmojiTag(mark, path);
                        _MessageTextTagTable.Add(emojiTag);
                        emojiTag.Rise = - descent;
                        buffer.ApplyTag(emojiTag, beforeIter, afterIter);
                        return false;
                    });
                },
                (ex) => {
                    GLib.Idle.Add(delegate {
                        var markIter = buffer.GetIterAtMark(mark);
                        buffer.DeleteMark(mark);
                        AddAlternativeText(buffer, ref markIter, imgPart);
                        return false;
                    });
                }
            );
        }
Beispiel #18
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
            #if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
            #endif

            if (msg == null) {
                throw new ArgumentNullException("msg");
            }

            var buffer = Buffer;
            var iter = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);

            var senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag = null;
            if (senderPrefixWidth != 0) {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null) {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps) {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null) {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0) {
                        var dayLine = new MessageBuilder().
                            AppendEventPrefix();
                        if (span.Days > 1) {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        } else {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format)) {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null) {
                    InsertTimeStamp(buffer, ref iter, timestamp, msg);

                    // apply timestamp width to indent tag
                    if (indentTag != null) {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts) {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight) {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (UrlMessagePartModel) msgPart);
                } else if (msgPart is TextMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (TextMessagePartModel) msgPart);
                } else if (msgPart is ImageMessagePartModel) {
                    InsertToBuffer(buffer, ref iter, (ImageMessagePartModel) msgPart);
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event) {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null) {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null) {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak) {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17) {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null) {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null) {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight) {
                if (MessageHighlighted != null) {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
Beispiel #19
0
 protected virtual void OnSourceMarkUpdated(Gtk.TextMark p0)
 {
     InternalSourceMarkUpdated(p0);
 }
Beispiel #20
0
        public ChatView(ChatModel chat)
        {
            Trace.Call(chat);

            _ChatModel = chat;

            IsAutoScrolling = true;
            MessageTextView tv = new MessageTextView();
            _EndMark = tv.Buffer.CreateMark("end", tv.Buffer.EndIter, false);
            tv.ShowTimestamps = true;
            tv.ShowMarkerline = true;
            tv.Editable = false;
            tv.CursorVisible = true;
            tv.WrapMode = Gtk.WrapMode.Char;
            tv.MessageAdded += OnMessageTextViewMessageAdded;
            tv.MessageHighlighted += OnMessageTextViewMessageHighlighted;
            tv.PopulatePopup += OnMessageTextViewPopulatePopup;
            tv.SizeRequested += delegate {
                AutoScroll();
            };
            tv.PersonClicked += OnMessageTextViewPersonClicked;
            _OutputMessageTextView = tv;

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            _OutputScrolledWindow = sw;
            //sw.HscrollbarPolicy = Gtk.PolicyType.Never;
            sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
            sw.VscrollbarPolicy = Gtk.PolicyType.Always;
            sw.ShadowType = Gtk.ShadowType.In;
            sw.Vadjustment.ValueChanged += OnVadjustmentValueChanged;
            sw.Add(_OutputMessageTextView);

            // popup menu
            _TabMenu = new Gtk.Menu();
            _TabMenu.Shown += OnTabMenuShown;

            //FocusChild = _OutputTextView;
            //CanFocus = false;

            _TabLabel = new Gtk.Label();

            TabImage = DefaultTabImage;
            _TabHBox = new Gtk.HBox();
            _TabHBox.PackEnd(new Gtk.Fixed(), true, true, 0);
            _TabHBox.PackEnd(_TabLabel, false, false, 0);
            _TabHBox.PackStart(TabImage, false, false, 2);
            _TabHBox.ShowAll();

            _TabEventBox = new Gtk.EventBox();
            _TabEventBox.VisibleWindow = false;
            _TabEventBox.ButtonPressEvent += new Gtk.ButtonPressEventHandler(OnTabButtonPress);
            _TabEventBox.Add(_TabHBox);
            _TabEventBox.ShowAll();

            _ThemeSettings = new ThemeSettings();

            // OPT-TODO: this should use a TaskStack instead of TaskQueue
            _LastSeenHighlightQueue = new TaskQueue("LastSeenHighlightQueue("+ID+")");
            _LastSeenHighlightQueue.AbortedEvent += OnLastSeenHighlightQueueAbortedEvent;
            _LastSeenHighlightQueue.ExceptionEvent += OnLastSeenHighlightQueueExceptionEvent;
        }
Beispiel #21
0
        public ChatView(ChatModel chat)
        {
            Trace.Call(chat);

            _ChatModel = chat;
            _Name = _ChatModel.Name;
            Name = _Name;

            // TextTags
            Gtk.TextTagTable ttt = new Gtk.TextTagTable();
            _OutputTextTagTable = ttt;
            Gtk.TextTag tt;
            Pango.FontDescription fd;

            tt = new Gtk.TextTag("bold");
            fd = new Pango.FontDescription();
            fd.Weight = Pango.Weight.Bold;
            tt.FontDesc = fd;
            ttt.Add(tt);

            tt = new Gtk.TextTag("italic");
            fd = new Pango.FontDescription();
            fd.Style = Pango.Style.Italic;
            tt.FontDesc = fd;
            ttt.Add(tt);

            tt = new Gtk.TextTag("underline");
            tt.Underline = Pango.Underline.Single;
            ttt.Add(tt);

            tt = new Gtk.TextTag("url");
            tt.Underline = Pango.Underline.Single;
            tt.Foreground = "darkblue";
            tt.TextEvent += new Gtk.TextEventHandler(_OnTextTagUrlTextEvent);
            fd = new Pango.FontDescription();
            tt.FontDesc = fd;
            ttt.Add(tt);

            Gtk.TextView tv = new Gtk.TextView();
            tv.Buffer = new Gtk.TextBuffer(ttt);
            _EndMark = tv.Buffer.CreateMark("end", tv.Buffer.EndIter, false);
            tv.Editable = false;
            //tv.CursorVisible = false;
            tv.CursorVisible = true;
            tv.WrapMode = Gtk.WrapMode.Char;
            tv.Buffer.Changed += new EventHandler(_OnTextBufferChanged);
            tv.MotionNotifyEvent += new Gtk.MotionNotifyEventHandler(_OnMotionNotifyEvent);
            _OutputTextView = tv;

            Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow();
            //sw.HscrollbarPolicy = Gtk.PolicyType.Never;
            sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
            sw.VscrollbarPolicy = Gtk.PolicyType.Always;
            sw.ShadowType = Gtk.ShadowType.In;
            sw.Add(_OutputTextView);
            _OutputScrolledWindow = sw;

            // popup menu
            _TabMenu = new Gtk.Menu();

            Gtk.ImageMenuItem close_item = new Gtk.ImageMenuItem(Gtk.Stock.Close, null);
            close_item.Activated += new EventHandler(OnTabMenuCloseActivated);
            _TabMenu.Append(close_item);

            //FocusChild = _OutputTextView;
            //CanFocus = false;

            _TabLabel = new Gtk.Label();
            _TabLabel.Text = _Name;

            _TabHBox = new Gtk.HBox();
            _TabHBox.PackEnd(new Gtk.Fixed(), true, true, 0);
            _TabHBox.PackEnd(_TabLabel, false, false, 0);
            _TabHBox.ShowAll();

            _TabEventBox = new Gtk.EventBox();
            _TabEventBox.VisibleWindow = false;
            _TabEventBox.ButtonPressEvent += new Gtk.ButtonPressEventHandler(OnTabButtonPress);
            _TabEventBox.Add(_TabHBox);
            _TabEventBox.ShowAll();
        }
Beispiel #22
0
        void AddEmoji(Gtk.TextBuffer buffer, ref Gtk.TextIter iter, ImageMessagePartModel imgPart, string shortName)
        {
            var unicode = Emojione.ShortnameToUnicode(shortName);

            if (unicode == null)
            {
                AddAlternativeText(buffer, ref iter, imgPart);
                return;
            }

            int width, height;
            int descent;

            using (var layout = CreatePangoLayout(null)) {
                layout.GetPixelSize(out width, out height);
                descent = layout.Context.GetMetrics(layout.FontDescription, null).Descent;
            }

            // A mark here serves two pusposes. One is to allow us to apply the
            // tag across the pixbuf. It also lets us know later where to put
            // the pixbuf if we need to load it from the network
            var mark = new Gtk.TextMark(null, true);

            buffer.AddMark(mark, iter);

            var    emojiName = unicode + ".png";
            string emojiPath;

            if (EmojiCache.TryGetIcon("emojione", emojiName, out emojiPath))
            {
                var emojiFile = new FileInfo(emojiPath);
                if (emojiFile.Exists && emojiFile.Length > 0)
                {
                    var pix = new Gdk.Pixbuf(emojiPath, -1, height);
                    buffer.InsertPixbuf(ref iter, pix);
                    var beforeIter = buffer.GetIterAtMark(mark);
                    var imgTag     = new EmojiTag(mark, emojiFile.FullName);
                    imgTag.Rise = -descent;
                    _MessageTextTagTable.Add(imgTag);
                    buffer.ApplyTag(imgTag, beforeIter, iter);
                }
                else
                {
                    AddAlternativeText(buffer, ref iter, imgPart);
                }

                return;
            }

            var emojiUrl = Emojione.UnicodeToUrl(unicode);

            EmojiCache.BeginDownloadFile("emojione", emojiName, emojiUrl,
                                         (path) => {
                GLib.Idle.Add(delegate {
                    var afterIter = buffer.GetIterAtMark(mark);
                    buffer.InsertPixbuf(ref afterIter, new Gdk.Pixbuf(path, -1, height));
                    var beforeIter = buffer.GetIterAtMark(mark);
                    var emojiTag   = new EmojiTag(mark, path);
                    _MessageTextTagTable.Add(emojiTag);
                    emojiTag.Rise = -descent;
                    buffer.ApplyTag(emojiTag, beforeIter, afterIter);
                    return(false);
                });
            },
                                         (ex) => {
                GLib.Idle.Add(delegate {
                    var markIter = buffer.GetIterAtMark(mark);
                    buffer.DeleteMark(mark);
                    AddAlternativeText(buffer, ref markIter, imgPart);
                    return(false);
                });
            }
                                         );
        }
Beispiel #23
0
		public override void OnNoteOpened ()
		{
			// NOTE: This hack helps avoid multiple URL opens
			// now that Notes always perform
			// TagTable sharing.  This is because if the TagTable is
			// shared, we will connect to the same Tag's event
			// source each time a note is opened, and get called
			// multiple times for each button press.  Fixes bug
			// #305813.
			if (!text_event_connected) {
				Note.TagTable.UrlTag.Activated += OnUrlTagActivated;
				text_event_connected = true;
			}

			click_mark = Buffer.CreateMark (null, Buffer.StartIter, true);

			Buffer.InsertText += OnInsertText;
			Buffer.DeleteRange += OnDeleteRange;

			Window.Editor.ButtonPressEvent += OnButtonPress;
			Window.Editor.PopulatePopup += OnPopulatePopup;
			Window.Editor.PopupMenu += OnPopupMenu;
		}
Beispiel #24
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
#if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
#endif

            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            var buffer    = Buffer;
            var iter      = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);


            var         senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag         = null;
            if (senderPrefixWidth != 0)
            {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null)
                {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps)
            {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null)
                {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span             = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0)
                    {
                        var dayLine = new MessageBuilder().
                                      AppendEventPrefix();
                        if (span.Days > 1)
                        {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        }
                        else
                        {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format))
                    {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null)
                {
                    InsertTimeStamp(buffer, ref iter, timestamp, msg);

                    // apply timestamp width to indent tag
                    if (indentTag != null)
                    {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts)
            {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight)
                {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel)
                {
                    InsertToBuffer(buffer, ref iter, (UrlMessagePartModel)msgPart);
                }
                else if (msgPart is TextMessagePartModel)
                {
                    InsertToBuffer(buffer, ref iter, (TextMessagePartModel)msgPart);
                }
                else if (msgPart is ImageMessagePartModel)
                {
                    InsertToBuffer(buffer, ref iter, (ImageMessagePartModel)msgPart);
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event)
            {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null)
            {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null)
            {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter  = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak)
            {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17)
            {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null)
            {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null)
            {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight)
            {
                if (MessageHighlighted != null)
                {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
Beispiel #25
0
        void SetLineText(string text, Gtk.TextMark mark)
        {
            var start = DeleteLineAtMark(mark);

            view.Buffer.Insert(ref start, text + "\n");
        }
Beispiel #26
0
 public StartState(Gtk.TextMark mark, int data)
 {
     Mark = mark;
     Data = data;
 }
Beispiel #27
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
            #if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
            #endif

            if (msg == null) {
                throw new ArgumentNullException("msg");
            }

            var buffer = Buffer;
            var iter = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);

            var senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag = null;
            if (senderPrefixWidth != 0) {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null) {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps) {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null) {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0) {
                        var dayLine = new MessageBuilder().
                            AppendEventPrefix();
                        if (span.Days > 1) {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        } else {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format)) {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null) {
                    timestamp = String.Format("{0} ", timestamp);
                    buffer.Insert(ref iter, timestamp);

                    // apply timestamp width to indent tag
                    if (indentTag != null) {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts) {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight) {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel) {
                    var urlPart = (UrlMessagePartModel) msgPart;
                    var linkText = urlPart.Text ?? urlPart.Url;

                    var url = urlPart.Url;
                    Uri uri;
                    try {
                        uri = new Uri(url);
                    } catch (UriFormatException ex) {
            #if LOG4NET
                        _Logger.Error("AddMessage(): Invalid URL: " + url, ex);
            #endif
                        buffer.Insert(ref iter, linkText);
                        continue;
                    }

                    var tags = new List<Gtk.TextTag>();
                    // link URI tag
                    var linkTag = new LinkTag(uri);
                    linkTag.TextEvent += OnLinkTagTextEvent;
                    _MessageTextTagTable.Add(linkTag);
                    tags.Add(linkTag);

                    // link style tag
                    tags.Add(LinkTag);

                    buffer.InsertWithTags(ref iter, linkText, tags.ToArray());
                } else if (msgPart is TextMessagePartModel) {
                    var tags = new List<Gtk.TextTag>();
                    TextMessagePartModel fmsgti = (TextMessagePartModel) msgPart;
                    if (fmsgti.ForegroundColor != TextColor.None) {
                        var bg = ColorConverter.GetTextColor(BackgroundColor);
                        if (fmsgti.BackgroundColor != TextColor.None) {
                            bg = fmsgti.BackgroundColor;
                        }
                        TextColor color = TextColorTools.GetBestTextColor(
                            fmsgti.ForegroundColor, bg
                        );
                        string tagname = GetTextTagName(color, null);
                        var tag = _MessageTextTagTable.Lookup(tagname);
                        tags.Add(tag);
                    }
                    if (fmsgti.BackgroundColor != TextColor.None) {
                        // TODO: get this from ChatView
                        string tagname = GetTextTagName(null, fmsgti.BackgroundColor);
                        var tag = _MessageTextTagTable.Lookup(tagname);
                        tags.Add(tag);
                    }
                    if (fmsgti.Underline) {
            #if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Underline is true");
            #endif
                        tags.Add(UnderlineTag);
                    }
                    if (fmsgti.Bold) {
            #if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Bold is true");
            #endif
                        tags.Add(BoldTag);
                    }
                    if (fmsgti.Italic) {
            #if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Italic is true");
            #endif
                        tags.Add(ItalicTag);
                    }

                    if (tags.Count > 0) {
                        buffer.InsertWithTags(ref iter, fmsgti.Text, tags.ToArray());
                    } else {
                        buffer.Insert(ref iter, fmsgti.Text);
                    }
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event) {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null) {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null) {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak) {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17) {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null) {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null) {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight) {
                if (MessageHighlighted != null) {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
Beispiel #28
0
        public void AddMessage(MessageModel msg, bool addLinebreak, bool showTimestamps)
        {
#if MSG_DEBUG
            Trace.Call(msg, addLinebreak);
#endif

            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            var buffer    = Buffer;
            var iter      = buffer.EndIter;
            var startMark = new Gtk.TextMark(null, true);
            buffer.AddMark(startMark, iter);


            var         senderPrefixWidth = GetSenderPrefixWidth(msg);
            Gtk.TextTag indentTag         = null;
            if (senderPrefixWidth != 0)
            {
                // TODO: re-use text tags that have the same indent width
                indentTag = new Gtk.TextTag(null)
                {
                    Indent = -senderPrefixWidth
                };
                _MessageTextTagTable.Add(indentTag);
            }

            if (showTimestamps)
            {
                var msgTimeStamp = msg.TimeStamp.ToLocalTime();
                if (_LastMessage != null)
                {
                    var lastMsgTimeStamp = _LastMessage.TimeStamp.ToLocalTime();
                    var span             = msgTimeStamp.Date - lastMsgTimeStamp.Date;
                    if (span.Days > 0)
                    {
                        var dayLine = new MessageBuilder().
                                      AppendEventPrefix();
                        if (span.Days > 1)
                        {
                            dayLine.AppendText(_("Day changed from {0} to {1}"),
                                               lastMsgTimeStamp.ToShortDateString(),
                                               msgTimeStamp.ToShortDateString());
                        }
                        else
                        {
                            dayLine.AppendText(_("Day changed to {0}"),
                                               msgTimeStamp.ToLongDateString());
                        }
                        dayLine.AppendText("\n");
                        var dayLineMsg = dayLine.ToMessage().ToString();
                        Buffer.InsertWithTags(ref iter, dayLineMsg, EventTag);
                    }
                }

                string timestamp = null;
                try {
                    string format = (string)Frontend.UserConfig["Interface/Notebook/TimestampFormat"];
                    if (!String.IsNullOrEmpty(format))
                    {
                        timestamp = msgTimeStamp.ToString(format);
                    }
                } catch (FormatException e) {
                    timestamp = "Timestamp Format ERROR: " + e.Message;
                }

                if (timestamp != null)
                {
                    timestamp = String.Format("{0} ", timestamp);
                    buffer.Insert(ref iter, timestamp);

                    // apply timestamp width to indent tag
                    if (indentTag != null)
                    {
                        indentTag.Indent -= GetPangoWidth(timestamp);
                    }
                }
            }

            var msgStartMark = new Gtk.TextMark(null, true);
            buffer.AddMark(msgStartMark, iter);

            bool hasHighlight = false;
            foreach (MessagePartModel msgPart in msg.MessageParts)
            {
                // supposed to be used only in a ChatView
                if (msgPart.IsHighlight)
                {
                    hasHighlight = true;
                }

                // TODO: implement all types
                if (msgPart is UrlMessagePartModel)
                {
                    var urlPart  = (UrlMessagePartModel)msgPart;
                    var linkText = urlPart.Text ?? urlPart.Url;

                    Uri uri;
                    try {
                        uri = new Uri(urlPart.Url);
                    } catch (UriFormatException ex) {
#if LOG4NET
                        _Logger.Error("AddMessage(): Invalid URL: " + urlPart.Url, ex);
#endif
                        buffer.Insert(ref iter, linkText);
                        continue;
                    }

                    var tags = new List <Gtk.TextTag>();
                    // link URI tag
                    var linkTag = new LinkTag(uri);
                    linkTag.TextEvent += OnLinkTagTextEvent;
                    _MessageTextTagTable.Add(linkTag);
                    tags.Add(linkTag);

                    // link style tag
                    tags.Add(LinkTag);

                    buffer.InsertWithTags(ref iter, linkText, tags.ToArray());
                }
                else if (msgPart is TextMessagePartModel)
                {
                    var tags = new List <Gtk.TextTag>();
                    TextMessagePartModel fmsgti = (TextMessagePartModel)msgPart;
                    if (fmsgti.ForegroundColor != TextColor.None)
                    {
                        var bg = ColorConverter.GetTextColor(BackgroundColor);
                        if (fmsgti.BackgroundColor != TextColor.None)
                        {
                            bg = fmsgti.BackgroundColor;
                        }
                        TextColor color = TextColorTools.GetBestTextColor(
                            fmsgti.ForegroundColor, bg
                            );
                        string tagname = GetTextTagName(color, null);
                        var    tag     = _MessageTextTagTable.Lookup(tagname);
                        tags.Add(tag);
                    }
                    if (fmsgti.BackgroundColor != TextColor.None)
                    {
                        // TODO: get this from ChatView
                        string tagname = GetTextTagName(null, fmsgti.BackgroundColor);
                        var    tag     = _MessageTextTagTable.Lookup(tagname);
                        tags.Add(tag);
                    }
                    if (fmsgti.Underline)
                    {
#if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Underline is true");
#endif
                        tags.Add(UnderlineTag);
                    }
                    if (fmsgti.Bold)
                    {
#if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Bold is true");
#endif
                        tags.Add(BoldTag);
                    }
                    if (fmsgti.Italic)
                    {
#if LOG4NET && MSG_DEBUG
                        _Logger.Debug("AddMessage(): fmsgti.Italic is true");
#endif
                        tags.Add(ItalicTag);
                    }

                    if (tags.Count > 0)
                    {
                        buffer.InsertWithTags(ref iter, fmsgti.Text, tags.ToArray());
                    }
                    else
                    {
                        buffer.Insert(ref iter, fmsgti.Text);
                    }
                }
            }
            var startIter = buffer.GetIterAtMark(startMark);
            if (msg.MessageType == MessageType.Event)
            {
                buffer.ApplyTag(EventTag, startIter, iter);
            }
            if (indentTag != null)
            {
                buffer.ApplyTag(indentTag, startIter, iter);
            }
            var nick = msg.GetNick();
            if (nick != null)
            {
                // TODO: re-use the same person tag for the same nick
                var personTag = new PersonTag(nick, nick);
                personTag.TextEvent += OnPersonTagTextEvent;
                _MessageTextTagTable.Add(personTag);

                var msgStartIter = buffer.GetIterAtMark(msgStartMark);
                var nickEndIter  = msgStartIter;
                nickEndIter.ForwardChars(nick.Length + 2);
                buffer.ApplyTag(PersonTag, msgStartIter, nickEndIter);
                buffer.ApplyTag(personTag, msgStartIter, nickEndIter);
            }
            buffer.DeleteMark(startMark);
            buffer.DeleteMark(msgStartMark);
            if (addLinebreak)
            {
                buffer.Insert(ref iter, "\n");
            }

            CheckBufferSize();

            if (IsGtk2_17)
            {
                // HACK: force a redraw of the widget, as for some reason
                // GTK+ 2.17.6 is not redrawing some lines we add here, especially
                // for local messages. See:
                // http://projects.qnetp.net/issues/show/185
                QueueDraw();
            }
            if (Frontend.IsWindows && _LastMessage == null)
            {
                // HACK: workaround rendering issue on Windows where the
                // first inserted text is not showing up until the next insert
                QueueDraw();
            }

            if (MessageAdded != null)
            {
                MessageAdded(this, new MessageTextViewMessageAddedEventArgs(msg));
            }

            if (hasHighlight)
            {
                if (MessageHighlighted != null)
                {
                    MessageHighlighted(this, new MessageTextViewMessageHighlightedEventArgs(msg));
                }
            }

            _LastMessage = msg;
        }
		protected override void UpdateInputLineBegin ()
		{
			if (tokenBeginMark == null)
				tokenBeginMark = Buffer.CreateMark (null, Buffer.EndIter, true);
			else
				Buffer.MoveMark (tokenBeginMark, Buffer.EndIter);

			base.UpdateInputLineBegin ();
		}
Beispiel #30
0
 public StartState(Gtk.TextMark mark, int data)
 {
     Mark = mark;
     Data = data;
 }