示例#1
0
        private void CreateTag(string name)
        {
            Random r = new Random();

            Gtk.Application.Invoke(delegate
            {
                if (tags.Contains(name))
                {
                    return;
                }

                Gdk.Color c = new Gdk.Color(
                    Convert.ToByte(r.Next(0, 256)),
                    Convert.ToByte(r.Next(0, 256)),
                    Convert.ToByte(r.Next(0, 256)));

                Gtk.TextTag tag = new Gtk.TextTag(name);
                chatview.Buffer.TagTable.Add(tag);
                tag.ForegroundGdk = c;
                tag.Weight        = Pango.Weight.Bold;

                Gtk.TextTag tag1 = new Gtk.TextTag(name);
                usersview.Buffer.TagTable.Add(tag1);
                tag1.ForegroundGdk = c;
                tag1.Weight        = Pango.Weight.Bold;

                tags.Add(name);
            });
        }
示例#2
0
        private void AddTags()
        {
            Gtk.TextTag tag = new Gtk.TextTag("default");
            chatview.Buffer.TagTable.Add(tag);

            CreateTag(src.Username);
        }
示例#3
0
        public void AppendTextWithoutScroll(Gtk.TextView t, string text)
        {
            Gtk.TextIter iter;
            //t.Buffer.MoveMark(t.Buffer.InsertMark, t.Buffer.EndIter);
            if (text != null)
            {
                if (text.Equals("") == false)
                {
                    iter = t.Buffer.EndIter;
                    Gtk.TextTag tag = new Gtk.TextTag("bold");
                    tag.Weight     = Pango.Weight.Bold;
                    tag.Foreground = this.rcSettings.ColorChatBold;
                    tag.SizePoints = this.rcSettings.ChatFontSize;
                    t.Buffer.TagTable.Add(tag);
                    tag            = new Gtk.TextTag("font");
                    tag.SizePoints = this.rcSettings.ChatFontSize;
                    tag.Foreground = this.rcSettings.ColorChat;
                    t.Buffer.TagTable.Add(tag);

                    string time = text.Substring(0, text.IndexOf("]") + 1);
                    text = text.Substring(text.IndexOf("]") + 1);
                    t.Buffer.InsertWithTagsByName(ref iter, time, "bold");
                    t.Buffer.InsertWithTagsByName(ref iter, text.Substring(0, text.IndexOf(":") + 1), "bold");
                    t.Buffer.InsertWithTagsByName(ref iter, text.Substring(text.IndexOf(":") + 1), "font");
                }
            }
            iter = t.Buffer.EndIter;
            t.Buffer.Insert(iter, "\n");
        }
示例#4
0
        public void AppendTextWithoutScroll(Gtk.TextView t, string text)
        {
            Gtk.TextIter iter;
            //t.Buffer.MoveMark(t.Buffer.InsertMark, t.Buffer.EndIter);
            if (text != null)
            {
                if (text.Equals("") == false)
                {
                    iter = t.Buffer.EndIter;
                    Gtk.TextTag tag = new Gtk.TextTag("bold");
                    tag.Weight = Pango.Weight.Bold;
                    tag.Foreground = this.rcSettings.ColorChatBold;
                    tag.SizePoints = this.rcSettings.ChatFontSize;
                    t.Buffer.TagTable.Add(tag);
                    tag = new Gtk.TextTag("font");
                    tag.SizePoints = this.rcSettings.ChatFontSize;
                    tag.Foreground = this.rcSettings.ColorChat;
                    t.Buffer.TagTable.Add(tag);

                    string time = text.Substring(0, text.IndexOf("]") + 1);
                    text = text.Substring(text.IndexOf("]") + 1);
                    t.Buffer.InsertWithTagsByName(ref iter, time, "bold");
                    t.Buffer.InsertWithTagsByName(ref iter, text.Substring(0, text.IndexOf(":") + 1), "bold");
                    t.Buffer.InsertWithTagsByName(ref iter, text.Substring(text.IndexOf(":") + 1),"font");

                }
            }
            iter = t.Buffer.EndIter;
            t.Buffer.Insert(iter, "\n");
        }
示例#5
0
        void ApplyTag(string name, string variation, Gtk.TextIter start, Gtk.TextIter end, Action <Gtk.TextTag> apply)
        {
            var buffer       = Control.Buffer;
            var prefix       = name + "-";
            var tagName      = prefix + variation;
            var tagsToRemove = new List <Gtk.TextTag>();

            buffer.TagTable.Foreach(t =>
            {
                if (t.Name != null && t.Name.StartsWith(prefix, StringComparison.Ordinal))
                {
                    tagsToRemove.Add(t);
                }
            });
            foreach (var removeTag in tagsToRemove)
            {
                buffer.RemoveTag(removeTag, start, end);
            }

            var tag = buffer.TagTable.Lookup(tagName);

            if (tag == null)
            {
                tag = new Gtk.TextTag(tagName);
                apply(tag);
                buffer.TagTable.Add(tag);
            }
            buffer.ApplyTag(tag, start, end);
        }
示例#6
0
        public bool Add(Gtk.TextTag tag)
        {
            bool raw_ret = gtk_text_tag_table_add(Handle, tag == null ? IntPtr.Zero : tag.Handle);
            bool ret     = raw_ret;

            return(ret);
        }
示例#7
0
 public static bool TagIsUndoable(Gtk.TextTag tag)
 {
     if (tag is NoteTag)
     {
         return(((NoteTag)tag).CanUndo);
     }
     return(false);
 }
示例#8
0
    static InfoPanelUtils()
    {
        redTag            = new Gtk.TextTag("red-foreground");
        redTag.Foreground = "#ff2828";

        blueTag            = new Gtk.TextTag("blue-foreground");
        blueTag.Foreground = "#3333ff";
    }
示例#9
0
 public static bool TagIsSpellCheckable(Gtk.TextTag tag)
 {
     if (tag is NoteTag)
     {
         return(((NoteTag)tag).CanSpellCheck);
     }
     return(false);
 }
示例#10
0
 public static bool TagIsActivatable(Gtk.TextTag tag)
 {
     if (tag is NoteTag)
     {
         return(((NoteTag)tag).CanActivate);
     }
     return(false);
 }
 static InfoPanelUtils()
 {
     redTag = new Gtk.TextTag("red-foreground");
     redTag.Foreground = "#ff2828";
     
     blueTag = new Gtk.TextTag("blue-foreground");
     blueTag.Foreground = "#3333ff";
 }
示例#12
0
文件: Utils.cs 项目: thioshp/tomboy
        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);
        }
示例#13
0
 public static bool TagIsGrowable(Gtk.TextTag tag)
 {
     if (tag is NoteTag)
     {
         return(((NoteTag)tag).CanGrow);
     }
     return(false);
 }
示例#14
0
 private static void ShowTextView(Gtk.TextView textView, string errorMessage, Gtk.TextTag tag)
 {
     textView.Visible     = true;
     textView.Buffer.Text = errorMessage;
     Gtk.TextIter start, end;
     textView.Buffer.GetBounds(out start, out end);
     textView.Buffer.ApplyTag(tag, start, end);
 }
示例#15
0
 public static bool TagIsSerializable(Gtk.TextTag tag)
 {
     if (tag is NoteTag)
     {
         return(((NoteTag)tag).CanSerialize);
     }
     return(false);
 }
示例#16
0
        public static bool TagHasDepth(Gtk.TextTag tag)
        {
            if (tag is DepthNoteTag)
            {
                return(true);
            }

            return(false);
        }
 public override void CommitMessageTextViewHook(Gtk.TextView textView)
 {
     this.textView                 = textView;
     overflowTextTag               = new Gtk.TextTag("overflow");
     overflowTextTag.Foreground    = "red";
     overflowTextTag.ForegroundSet = true;
     textView.Buffer.TagTable.Add(overflowTextTag);
     textView.Buffer.Changed += OnTextChanged;
 }
 public override void CommitMessageTextViewHook(Gtk.TextView textView)
 {
     this.textView                 = textView;
     overflowTextTag               = new Gtk.TextTag("overflow");
     overflowTextTag.Foreground    = Ide.Gui.Styles.ErrorForegroundColor.ToHexString(false);
     overflowTextTag.ForegroundSet = true;
     textView.Buffer.TagTable.Add(overflowTextTag);
     textView.Buffer.Changed += OnTextChanged;
 }
示例#19
0
        public static Gtk.TextTag TagNew(string name)
        {
            IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name);
            IntPtr raw_ret     = gtk_source_tag_new(native_name);

            Gtk.TextTag ret = GLib.Object.GetObject(raw_ret) as Gtk.TextTag;
            GLib.Marshaller.Free(native_name);
            return(ret);
        }
示例#20
0
        public Gtk.TextTag Lookup(string name)
        {
            IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name);
            IntPtr raw_ret     = gtk_text_tag_table_lookup(Handle, native_name);

            Gtk.TextTag ret = GLib.Object.GetObject(raw_ret) as Gtk.TextTag;
            GLib.Marshaller.Free(native_name);
            return(ret);
        }
示例#21
0
        private void InternalTagRemoved(Gtk.TextTag tag)
        {
            TagRemovedNativeDelegate unmanaged = class_abi.BaseOverride <TagRemovedNativeDelegate>(this.LookupGType(), "tag_removed");

            if (unmanaged == null)
            {
                return;
            }

            unmanaged(this.Handle, tag == null ? IntPtr.Zero : tag.Handle);
        }
示例#22
0
        protected override void OnTagRemoved(Gtk.TextTag tag)
        {
            added_tags.Remove(tag);

            NoteTag note_tag = tag as NoteTag;

            if (note_tag != null)
            {
                note_tag.Changed -= OnTagChanged;
            }
        }
示例#23
0
            public void EmitEndLink()
            {
                var link = openLinks.Pop();
                var tag  = new Gtk.TextTag(null);

                tag.Underline     = Pango.Underline.Single;
                tag.ForegroundGdk = Toolkit.CurrentEngine.Defaults.FallbackLinkColor.ToGtkValue();
                TagTable.Add(tag);
                ApplyTag(tag, GetIterAtMark(link.StartMark), EndIter);
                Links[tag] = link;
            }
示例#24
0
        public static Gtk.TextTag LineCommentTagNew(string id, string name, string pattern_start)
        {
            IntPtr native_id            = GLib.Marshaller.StringToPtrGStrdup(id);
            IntPtr native_name          = GLib.Marshaller.StringToPtrGStrdup(name);
            IntPtr native_pattern_start = GLib.Marshaller.StringToPtrGStrdup(pattern_start);
            IntPtr raw_ret = gtk_line_comment_tag_new(native_id, native_name, native_pattern_start);

            Gtk.TextTag ret = GLib.Object.GetObject(raw_ret) as Gtk.TextTag;
            GLib.Marshaller.Free(native_id);
            GLib.Marshaller.Free(native_name);
            GLib.Marshaller.Free(native_pattern_start);
            return(ret);
        }
示例#25
0
        void TextView_AddTag(string name, string foreground)
        {
            var tag = new Gtk.TextTag(name);

            tag.Foreground = foreground;

            /*Color clr = new Color();
            *  Color.Parse(foreground, ref clr);
            *  tag.ForegroundGdk = clr;*/
            tag.ForegroundSet = true;
            tag.Weight        = Pango.Weight.Bold;
            tag.WeightSet     = true;
            tableResultText.Buffer.TagTable.Add(tag);
        }
示例#26
0
        private void InternalTagRemoved(Gtk.TextTag tag)
        {
            TagRemovedNativeDelegate unmanaged = null;

            unsafe {
                IntPtr *raw_ptr = (IntPtr *)(((long)this.LookupGType().GetThresholdType().GetClassPtr()) + (long)class_abi.GetFieldOffset("tag_removed"));
                unmanaged = (TagRemovedNativeDelegate)Marshal.GetDelegateForFunctionPointer(*raw_ptr, typeof(TagRemovedNativeDelegate));
            }
            if (unmanaged == null)
            {
                return;
            }

            unmanaged(this.Handle, tag == null ? IntPtr.Zero : tag.Handle);
        }
示例#27
0
        public static Gtk.TextTag StringTagNew(string id, string name, string pattern_start, string pattern_end, bool end_at_line_end)
        {
            IntPtr native_id            = GLib.Marshaller.StringToPtrGStrdup(id);
            IntPtr native_name          = GLib.Marshaller.StringToPtrGStrdup(name);
            IntPtr native_pattern_start = GLib.Marshaller.StringToPtrGStrdup(pattern_start);
            IntPtr native_pattern_end   = GLib.Marshaller.StringToPtrGStrdup(pattern_end);
            IntPtr raw_ret = gtk_string_tag_new(native_id, native_name, native_pattern_start, native_pattern_end, end_at_line_end);

            Gtk.TextTag ret = GLib.Object.GetObject(raw_ret) as Gtk.TextTag;
            GLib.Marshaller.Free(native_id);
            GLib.Marshaller.Free(native_name);
            GLib.Marshaller.Free(native_pattern_start);
            GLib.Marshaller.Free(native_pattern_end);
            return(ret);
        }
示例#28
0
        public SessionWindow(ServerWindow parent)
            : base(Gtk.WindowType.Toplevel)
        {
            TransientFor = parent;

            this.Build();
            this.chatSendButton.TooltipMarkup = Catalog.GetString("Sends the message");
            this.startGameButton.TooltipMarkup = Catalog.GetString("Starts the game in this session");
            this.disconnectButton.TooltipMarkup = Catalog.GetString("Disconnects from the session");
            this.endSessionButton.TooltipMarkup = Catalog.GetString("Ends the session");

            listener = new EventListener(this);
            ConnectionManager.SessionEventListener.AddListener((IPlayerSessionEventListener)listener);
            ConnectionManager.SessionEventListener.AddListener((ISpectatorSessionEventListener)listener);
            ConnectionManager.OnGameConnected += () => {
                Gdk.Threads.Enter();
                startGameButton.Sensitive = false;
                Gdk.Threads.Leave();
            };

            ISession session = ConnectionManager.Session;
            IPlayerSessionControl playerControl = ConnectionManager.PlayerSessionControl;
            if(playerControl != null && playerControl.Player.IsCreator)
            {
                if(session.State != SessionState.Playing && session.State != SessionState.Ended)
                    startGameButton.Sensitive = true;
                else
                    startGameButton.Sensitive = false;
                endSessionButton.Sensitive = true;
            }
            else
            {
                startGameButton.Sensitive = false;
                endSessionButton.Sensitive = false;
            }
            Gtk.TextTag playerTag = new Gtk.TextTag("player");
            playerTag.Weight = Pango.Weight.Bold;
            playerTag.Foreground = "blue";

            Gtk.TextTag spectatorTag = new Gtk.TextTag("spectator");
            spectatorTag.Weight = Pango.Weight.Bold;
            spectatorTag.Foreground = "yellow";

            chatView.Buffer.TagTable.Add(playerTag);
            chatView.Buffer.TagTable.Add(spectatorTag);

            sessionInfoWidget.Session = ConnectionManager.Session;
        }
示例#29
0
 public static void Apply(this Font font, Gtk.TextTag tag)
 {
     if (tag != null)
     {
         if (font != null)
         {
             tag.Underline     = font.FontDecoration.HasFlag(FontDecoration.Underline) ? Pango.Underline.Single : Pango.Underline.None;
             tag.Strikethrough = font.FontDecoration.HasFlag(FontDecoration.Strikethrough);
         }
         else
         {
             tag.Underline     = Pango.Underline.None;
             tag.Strikethrough = false;
         }
     }
 }
示例#30
0
        /*
         * Helper methods
         */
        private Gtk.TextTagTable BuildTagTable()
        {
            // TextTags
            Gtk.TextTagTable      ttt = new Gtk.TextTagTable();
            Gtk.TextTag           tt;
            Pango.FontDescription fd;

            // WARNING: the insertion order of tags MATTERS!
            // The attributes of the text tags are applied in the order of
            // insertion to the text table, and not in which order the tags
            // applied in the buffer. This is sick IMHO.
            tt          = new Gtk.TextTag("bold");
            fd          = new Pango.FontDescription();
            fd.Weight   = Pango.Weight.Bold;
            tt.FontDesc = fd;
            BoldTag     = tt;
            ttt.Add(tt);

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

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

            tt            = new Gtk.TextTag("event");
            tt.Foreground = "darkgray";
            EventTag      = tt;
            ttt.Add(tt);

            tt            = new Gtk.TextTag("link");
            tt.Underline  = Pango.Underline.Single;
            tt.Foreground = "darkblue";
            LinkTag       = tt;
            ttt.Add(tt);

            tt        = new Gtk.TextTag("person");
            PersonTag = tt;
            ttt.Add(tt);

            return(ttt);
        }
示例#31
0
        public void AddSplitTag(Gtk.TextIter start,
                                Gtk.TextIter end,
                                Gtk.TextTag tag)
        {
            TagData data = new TagData();

            data.start = start.Offset;
            data.end   = end.Offset;
            data.tag   = tag;
            splitTags.Add(data);

            /*
             * The text chop will contain these tags, which means that when
             * the text is inserted again during redo, it will have the tag.
             */
            chop.RemoveTag(tag);
        }
示例#32
0
        private void ProcessIncomingMessage(ChatMessage message)
        {
            var messageDateTime = UNIX_EPOCH.AddSeconds(message.DateTime);

            Gtk.Application.Invoke((object sender, EventArgs e) => {
                var buffer = txtRoom.Buffer;
                var iter   = buffer.EndIter;

                var tag        = new Gtk.TextTag(null);
                tag.Weight     = Pango.Weight.Bold;
                tag.Foreground = "blue";

                buffer.TagTable.Add(tag);
                buffer.InsertWithTags(ref iter, messageDateTime.ToShortTimeString() + " - " + message.UserCredential.UserName + "\n", tag);
                buffer.Insert(ref iter, message.Text.Text + "\n\n");

                txtRoom.ScrollToMark(buffer.InsertMark, 0, true, 0, 1);
            });
        }
示例#33
0
 public void AppendTextWithoutScroll(string text)
 {
     Gtk.TextIter iter;
     this.textview1.Buffer.MoveMark(this.textview1.Buffer.InsertMark, this.textview1.Buffer.EndIter);
     if (text != null)
     {
         if (text.Equals("") == false)
         {
             iter = this.textview1.Buffer.EndIter;
             Gtk.TextTag tag = new Gtk.TextTag("bold");
             tag.Weight     = Pango.Weight.Bold;
             tag.Foreground = "#373349";
             this.textview1.Buffer.TagTable.Add(tag);
             this.textview1.Buffer.InsertWithTagsByName(ref iter, text.Substring(0, text.IndexOf(":", 10) + 1), "bold");
             this.textview1.Buffer.Insert(ref iter, text.Substring(text.IndexOf(":", 10) + 1));
         }
     }
     iter = this.textview1.Buffer.EndIter;
     this.textview1.Buffer.Insert(ref iter, "\n");
 }
示例#34
0
 public void AppendTextWithoutScroll(string text)
 {
     Gtk.TextIter iter;
     this.textview1.Buffer.MoveMark(this.textview1.Buffer.InsertMark, this.textview1.Buffer.EndIter);
     if (text != null)
     {
         if (text.Equals("") == false)
         {
             iter = this.textview1.Buffer.EndIter;
             Gtk.TextTag tag = new Gtk.TextTag("bold");
             tag.Weight = Pango.Weight.Bold;
             tag.Foreground = "#373349";
             this.textview1.Buffer.TagTable.Add(tag);
             this.textview1.Buffer.InsertWithTagsByName(ref iter, text.Substring(0,text.IndexOf(":",10) + 1),"bold");
             this.textview1.Buffer.Insert(ref iter, text.Substring(text.IndexOf(":", 10) + 1));
         }
     }
     iter = this.textview1.Buffer.EndIter;
     this.textview1.Buffer.Insert(ref iter, "\n");
 }
示例#35
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;
        }
        void build_tag_table()
        {
            logleveltag[0] = new Gtk.TextTag("Debug");
            logleveltag[1] = new Gtk.TextTag("Info");
            logleveltag[2] = new Gtk.TextTag("None");
            logleveltag[3] = new Gtk.TextTag("Warning");
            logleveltag[4] = new Gtk.TextTag("Error");

            logleveltag[0].ForegroundGdk = new Gdk.Color(0,0,0);
            logleveltag[1].ForegroundGdk = new Gdk.Color(38,34,232);
            logleveltag[2].ForegroundGdk = new Gdk.Color(232,134,192);
            logleveltag[3].ForegroundGdk = new Gdk.Color(243,147,10);
            logleveltag[4].ForegroundGdk = new Gdk.Color(255, 0, 0);
        }
示例#37
0
文件: ChatView.cs 项目: RoninBG/smuxi
        private string _GetTextTagName(TextColor fgColor, TextColor bgColor)
        {
            string hexcode;
             string tagname;
             if (fgColor != null) {
                hexcode = fgColor.HexCode;
                tagname = "fg_color:" + hexcode;
             } else if (bgColor != null) {
                hexcode = bgColor.HexCode;
                tagname = "bg_color:" + hexcode;
             } else {
                return null;
             }

             if (_OutputTextTagTable.Lookup(tagname) == null) {
                 int red   = Int16.Parse(hexcode.Substring(0, 2), NumberStyles.HexNumber);
                 int green = Int16.Parse(hexcode.Substring(2, 2), NumberStyles.HexNumber);
                 int blue  = Int16.Parse(hexcode.Substring(4, 2), NumberStyles.HexNumber);
                 Gdk.Color c = new Gdk.Color((byte)red, (byte)green, (byte)blue);
                 Gtk.TextTag tt = new Gtk.TextTag(tagname);
                 if (fgColor != null) {
                    tt.ForegroundGdk = c;
                 } else if (bgColor != null) {
                    tt.BackgroundGdk = c;
                 }
            #if LOG4NET
                 _Logger.Debug("_GetTextTagName(): adding: " + tagname + " to _OutputTextTagTable");
            #endif
                 _OutputTextTagTable.Add(tt);
             }
             return tagname;
        }
示例#38
0
文件: ChatView.cs 项目: RoninBG/smuxi
        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();
        }
示例#39
0
		public TagRemoveAction (Gtk.TextTag tag, Gtk.TextIter start, Gtk.TextIter end)
		{
			this.tag = tag;
			this.start = start.Offset;
			this.end = end.Offset;
		}
        void InitCommonTags ()
        {
            Gtk.TextTag tag;
            tag = new Gtk.TextTag ("bold");
            tag.Weight = Pango.Weight.Bold;
            Add (tag);

            tag = new Gtk.TextTag ("italic");
            tag.Style = Pango.Style.Italic;
            Add (tag);
        }
		public override void CommitMessageTextViewHook (Gtk.TextView textView)
		{
			this.textView = textView;
			overflowTextTag = new Gtk.TextTag ("overflow");
			overflowTextTag.Foreground = "red";
			overflowTextTag.ForegroundSet = true;
			textView.Buffer.TagTable.Add (overflowTextTag);
			textView.Buffer.Changed += OnTextChanged;
		}
示例#42
0
		public override void Initialize ()
		{
			broken_link_tag = Note.TagTable.Lookup ("link:broken");
		}
示例#43
0
		public override void Initialize ()
		{
			title_tag = Note.TagTable.Lookup ("note-title");
		}
示例#44
0
 public void EmitEndLink()
 {
     var link = openLinks.Pop ();
     var tag = new Gtk.TextTag (null);
     tag.Underline = Pango.Underline.Single;
     tag.ForegroundGdk = Toolkit.CurrentEngine.Defaults.FallbackLinkColor.ToGtkValue ();
     TagTable.Add (tag);
     ApplyTag (tag, GetIterAtMark (link.StartMark), EndIter);
     Links[tag] = link;
 }
示例#45
0
            public void EmitText(FormattedText markup)
            {
                var iterEnd = EndIter;
                var textmark = CreateMark (null, iterEnd, true);
                Insert (ref iterEnd, markup.Text);

                foreach (var attr in markup.Attributes) {
                    var iterEndAttr = GetIterAtMark (textmark);
                    iterEndAttr.ForwardChars (attr.StartIndex);
                    var attrStart = CreateMark (null, iterEndAttr, true);
                    iterEndAttr.ForwardChars (attr.Count);

                    var tag = new Gtk.TextTag (null);

                    if (attr is BackgroundTextAttribute) {
                        var xa = (BackgroundTextAttribute)attr;
                        tag.BackgroundGdk = xa.Color.ToGtkValue ();
                    } else if (attr is ColorTextAttribute) {
                        var xa = (ColorTextAttribute)attr;
                        tag.ForegroundGdk = xa.Color.ToGtkValue ();
                    } else if (attr is FontWeightTextAttribute) {
                        var xa = (FontWeightTextAttribute)attr;
                        tag.Weight = (Pango.Weight)(int)xa.Weight;
                    } else if (attr is FontStyleTextAttribute) {
                        var xa = (FontStyleTextAttribute)attr;
                        tag.Style = (Pango.Style)(int)xa.Style;
                    } else if (attr is UnderlineTextAttribute) {
                        var xa = (UnderlineTextAttribute)attr;
                        tag.Underline = xa.Underline ? Pango.Underline.Single : Pango.Underline.None;
                    } else if (attr is StrikethroughTextAttribute) {
                        var xa = (StrikethroughTextAttribute)attr;
                        tag.Strikethrough = xa.Strikethrough;
                    } else if (attr is FontTextAttribute) {
                        var xa = (FontTextAttribute)attr;
                        tag.FontDesc = (Pango.FontDescription)Toolkit.GetBackend (xa.Font);
                    } else if (attr is LinkTextAttribute) {
                        var xa = (LinkTextAttribute)attr;
                        Uri uri = xa.Target;
                        if (uri == null)
                            Uri.TryCreate (markup.Text.Substring (xa.StartIndex, xa.Count), UriKind.RelativeOrAbsolute, out uri);
                        var link = new Link { Href = uri };
                        tag.Underline = Pango.Underline.Single;
                        tag.ForegroundGdk = Toolkit.CurrentEngine.Defaults.FallbackLinkColor.ToGtkValue ();
                        Links [tag] = link;
                    }

                    TagTable.Add (tag);
                    ApplyTag (tag, GetIterAtMark (attrStart), iterEndAttr);
                    DeleteMark (attrStart);
                }
                DeleteMark (textmark);
            }
示例#46
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;
        }
示例#47
0
        /*
         * Helper methods
         */
        private Gtk.TextTagTable BuildTagTable()
        {
            // TextTags
            Gtk.TextTagTable ttt = new Gtk.TextTagTable();
            Gtk.TextTag tt;
            Pango.FontDescription fd;

            // WARNING: the insertion order of tags MATTERS!
            // The attributes of the text tags are applied in the order of
            // insertion to the text table, and not in which order the tags
            // applied in the buffer. This is sick IMHO.
            tt = new Gtk.TextTag("bold");
            fd = new Pango.FontDescription();
            fd.Weight = Pango.Weight.Bold;
            tt.FontDesc = fd;
            BoldTag = tt;
            ttt.Add(tt);

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

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

            tt = new Gtk.TextTag("event");
            tt.Foreground = "darkgray";
            EventTag = tt;
            ttt.Add(tt);

            tt = new Gtk.TextTag("link");
            tt.Underline = Pango.Underline.Single;
            tt.Foreground = "darkblue";
            LinkTag = tt;
            ttt.Add(tt);

            tt = new Gtk.TextTag("person");
            PersonTag = tt;
            ttt.Add(tt);

            return ttt;
        }
		public override void CommitMessageTextViewHook (Gtk.TextView textView)
		{
			this.textView = textView;
			overflowTextTag = new Gtk.TextTag ("overflow");
			overflowTextTag.Foreground = Ide.Gui.Styles.ErrorForegroundColor.ToHexString (false);
			overflowTextTag.ForegroundSet = true;
			textView.Buffer.TagTable.Add (overflowTextTag);
			textView.Buffer.Changed += OnTextChanged;
		}
示例#49
0
        private string GetTextTagName(TextColor fgColor, TextColor bgColor)
        {
            string hexcode;
             string tagname;
             if (fgColor != null) {
                hexcode = fgColor.HexCode;
                tagname = "fg_color:" + hexcode;
             } else if (bgColor != null) {
                hexcode = bgColor.HexCode;
                tagname = "bg_color:" + hexcode;
             } else {
                return null;
             }

             if (_MessageTextTagTable.Lookup(tagname) == null) {
                 int red   = Int16.Parse(hexcode.Substring(0, 2), NumberStyles.HexNumber);
                 int green = Int16.Parse(hexcode.Substring(2, 2), NumberStyles.HexNumber);
                 int blue  = Int16.Parse(hexcode.Substring(4, 2), NumberStyles.HexNumber);
                 Gdk.Color c = new Gdk.Color((byte)red, (byte)green, (byte)blue);
                 Gtk.TextTag tt = new Gtk.TextTag(tagname);
                 if (fgColor != null) {
                    tt.ForegroundGdk = c;
                 } else if (bgColor != null) {
                    tt.BackgroundGdk = c;
                 }
                 _MessageTextTagTable.Add(tt);
             }
             return tagname;
        }
示例#50
0
        /*
         * Helper methods
         */
        private Gtk.TextTagTable BuildTagTable()
        {
            // TextTags
            Gtk.TextTagTable ttt = new Gtk.TextTagTable();
            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 += OnTextTagUrlTextEvent;
            fd = new Pango.FontDescription();
            tt.FontDesc = fd;
            ttt.Add(tt);

            tt = new Gtk.TextTag("event");
            tt.Foreground = "darkgray";
            ttt.Add(tt);

            return ttt;
        }