Beispiel #1
0
    public void HilightWord()
    {
        Gtk.TextIter prevEndCharIter = new Gtk.TextIter();
        //Gtk.TextIter nextCharIter = new Gtk.TextIter ();

        if (!(endHilightIter.Equal(Gtk.TextIter.Zero)))
        {
            textBuffer.RemoveTag("hilight", startHilightIter, endHilightIter);
        }

        startHilightIter = startWordIter;
        endHilightIter   = endWordIter;
        prevEndCharIter  = endWordIter;
        prevEndCharIter.BackwardChar();
        while (Regex.IsMatch(startHilightIter.Char, @"[\s-]", RegexOptions.None))
        {
            startHilightIter.ForwardChar();
        }

        while (Regex.IsMatch(prevEndCharIter.Char, @"\s", RegexOptions.None) &&
               Regex.IsMatch(endHilightIter.Char, @"\S", RegexOptions.None))
        {
            endHilightIter.BackwardChar();
            prevEndCharIter.BackwardChar();
        }

        textBuffer.ApplyTag(tag, startHilightIter, endHilightIter);
        textView.ScrollToIter(endWordIter, 0, false, 0, 0);


        if (!running)
        {
            statusBar.Push(0, "Stopped at position " + startWordIter.Offset);
        }
    }
Beispiel #2
0
 private void FormatTextBuffer(TextBuffer textBuffer, XmlNode linkTextNode)
 {
     XmlNodeList childNodes = linkTextNode.ChildNodes;
        foreach(XmlNode childNode in childNodes)
        {
     if (childNode.Name.Equals("a"))
     {
      XmlAttribute href = childNode.Attributes["href"];
      if (href != null)
      {
       string textTagName = href.Value;
       TextTag textTag = textBuffer.TagTable.Lookup(textTagName);
       if (textTag != null)
       {
        TextMark startTagMark = textBuffer.CreateMark(textTagName, textBuffer.EndIter, true);
        textBuffer.InsertAtCursor(childNode.InnerText);
        TextIter startTagIter = textBuffer.GetIterAtMark(startTagMark);
        TextIter endTagIter = textBuffer.EndIter;
        textBuffer.ApplyTag(textTag, startTagIter, endTagIter);
       }
      }
      else
       textBuffer.InsertAtCursor(childNode.InnerText);
     }
     else
     {
      textBuffer.InsertAtCursor(childNode.InnerText);
     }
        }
        textBuffer.ApplyTag("small-font", textBuffer.StartIter, textBuffer.EndIter);
 }
        private void ApplyTextTags(Gtk.TextBuffer tb, string tagname)
        {
            int cN = tb.Text.Length - 1;

            Gtk.TextIter start = tb.GetIterAtOffset(0);
            Gtk.TextIter stop  = tb.GetIterAtOffset(cN);

            string[] delimiters    = new string[] { ":" };
            string[] tagname_parts = tagname.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
            string   key           = tagname_parts[0];
            string   value         = null;

            if (tagname_parts.Length > 1)
            {
                value = tagname_parts[1];
            }

            Gtk.TextTag tag_lookup = tb.TagTable.Lookup("DemoTextSelection");
            Gtk.TextTag tag_local  = null;
            // should be the same?!?!
            //tag_local = tag;		// class variable?? sometines null?
            tag_local = tag_lookup;


            Console.WriteLine("key [{0}] value[{1}] tagname [{2}]", key, value, tagname);
            switch (key)
            {
            case "font":
                tag_local.Font = value;
                break;

            case "fontsize":
                tag_local.Size = Convert.ToInt32(value);                         // events?!?!?
                break;

            case "fontweight":
                switch (value)
                {
                case "normal":
                    tag_local.Weight = Pango.Weight.Normal;
                    break;

                case "bold":
                    // tag_local.Weight = Pango.Weight.Bold; // no visible diff
                    tag_local.Weight = Pango.Weight.Ultrabold;
                    break;

                case "heavy":
                    tag_local.Weight = Pango.Weight.Heavy;
                    break;

                case "light":
                    tag_local.Weight = Pango.Weight.Light;
                    break;

                case "semibold":
                    tag_local.Weight = Pango.Weight.Semibold;
                    break;

                case "ultrabold":
                    tag_local.Weight = Pango.Weight.Ultrabold;
                    break;

                case "ultralight":
                    tag_local.Weight = Pango.Weight.Ultralight;
                    break;

                default:
                    tag_local.Weight = Pango.Weight.Normal;
                    break;
                }
                break;

            case "style":
                switch (value)
                {
                case "normal":
                    tag_local.Style = Pango.Style.Normal;
                    break;

                case "italic":
                    tag_local.Style = Pango.Style.Italic;
                    break;

                case "oblique":
                    tag_local.Style = Pango.Style.Oblique;
                    break;

                default:
                    tag_local.Style = Pango.Style.Normal;
                    break;
                }
                break;

            case "strikethrough":
                tag_local.Strikethrough = Convert.ToBoolean(value);
                break;

            case "doublestrikethrough":
                tag_local.Strikethrough = Convert.ToBoolean(value);
                break;

            case "superscript":
                if (Convert.ToBoolean(value))
                {
                    tag_local.Rise = 50;
                }
                else
                {
                    tag_local.Rise = 0;
                }
                break;

            case "subscript":
                if (Convert.ToBoolean(value))
                {
                    tag_local.Rise = -50;
                }
                else
                {
                    tag_local.Rise = 0;
                }
                break;

            case "smallcaps":
                if (Convert.ToBoolean(value))
                {
                    tag_local.Variant = Pango.Variant.SmallCaps;
                }
                else
                {
                    tag_local.Variant = Pango.Variant.Normal;
                }
                break;

            case "allcaps":
                // no all caps?
                // tamp replacement
                if (Convert.ToBoolean(value))
                {
                    tb.Text           = tb.Text.ToUpper();
                    tag_local.Variant = Pango.Variant.Normal;
                }
                else
                {
                    tb.Text           = this.demo_text;
                    tag_local.Variant = Pango.Variant.Normal;
                }
                break;

            case "hidden":
                if (Convert.ToBoolean(value))
                {
                    tag_local.Variant = Pango.Variant.Normal;
                }
                else
                {
                    tag_local.Rise = 0;
                }
                break;

            case "underlinestyle":
                switch (value)
                {
                case "none":
                    tag_local.Underline = Pango.Underline.None;
                    break;

                case "double":
                    tag_local.Underline = Pango.Underline.Double;
                    break;

                case "single":
                    tag_local.Underline = Pango.Underline.Single;
                    break;

                case "error":
                    tag_local.Underline = Pango.Underline.Error;
                    break;

                case "low":
                    tag_local.Underline = Pango.Underline.Low;
                    break;

                default:
                    tag_local.Underline = Pango.Underline.None;
                    break;
                }
                break;

            case "underlinecolor":
                // cannot change color of the underline!
                // tag_local.Underline
                // trying font until custom dialog is over
                string rgb = tagname_parts[2];                                          // obtained as "rgb:HHHH/HHHH/HHHH"

                //--------------------------------------------------------------------
                // Attempt 1
                tag_local.Foreground    = "";
                tag_local.ForegroundGdk = new Gdk.Color(60, 60, 60);
                //--------------------------------------------------------------------

                //--------------------------------------------------------------------
                // Attempt 2
                //textviewDemoText.ModifyFg(StateType.Normal, underline_color_selected);	// color not applied?!?!
                //textviewDemoText.ModifyBg(StateType.Normal, underline_color_selected);	// color not applied?!?!
                // return;		// to skip tb.ApplyTag later does not change color

                break;

            default:
                tag_local = tb.TagTable.Lookup(tagname);
                break;
            }

            tb.ApplyTag(tag_local, start, stop);

            return;
        }
Beispiel #4
0
		private void InsertText (TextBuffer buffer)
		{
			Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("gtk-logo-rgb.gif");
			pixbuf = pixbuf.ScaleSimple (32, 32, InterpType.Bilinear);

			// get start of buffer; each insertion will revalidate the
			// iterator to point to just after the inserted text.

			TextIter insertIter = buffer.StartIter;
			buffer.Insert (ref insertIter,
				       "The text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n");

			buffer.InsertWithTagsByName (ref insertIter, "Font styles. ", "heading");

			buffer.Insert (ref insertIter, "For example, you can have ");
			buffer.InsertWithTagsByName (ref insertIter, "italic", "italic");
		        buffer.Insert (ref insertIter, ", ");
			buffer.InsertWithTagsByName (ref insertIter, "bold", "bold");
		        buffer.Insert (ref insertIter, ", or ");
			buffer.InsertWithTagsByName (ref insertIter, "monospace (typewriter)", "monospace");
		        buffer.Insert (ref insertIter, ", or  ");
			buffer.InsertWithTagsByName (ref insertIter, "big", "big");
			buffer.Insert (ref insertIter, " text. ");
			buffer.Insert (ref insertIter,
				       "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ");
			buffer.InsertWithTagsByName (ref insertIter, "xx-small", "xx-small");
		        buffer.Insert (ref insertIter, " or");
			buffer.InsertWithTagsByName (ref insertIter, "x-large", "x-large");
			buffer.Insert (ref insertIter,
				       " to ensure that your program properly adapts if the user changes the default font size.\n\n");

			buffer.InsertWithTagsByName (ref insertIter, "Colors. ", "heading");

			buffer.Insert (ref insertIter, "Colors such as ");
			buffer.InsertWithTagsByName (ref insertIter, "a blue foreground", "blue_foreground");
		        buffer.Insert (ref insertIter, " or ");
			buffer.InsertWithTagsByName (ref insertIter, "a red background", "red_background");
		        buffer.Insert (ref insertIter, " or even ");
			buffer.InsertWithTagsByName (ref insertIter, "a stippled red background",
						     "red_background",
						     "background_stipple");

		        buffer.Insert (ref insertIter, " or ");
                        buffer.InsertWithTagsByName (ref insertIter,
						     "a stippled blue foreground on solid red background",
						     "blue_foreground",
						     "red_background",
						     "foreground_stipple");
		        buffer.Insert (ref insertIter, " (select that to read it) can be used.\n\n");

			buffer.InsertWithTagsByName (ref insertIter, "Underline, strikethrough, and rise. ", "heading");

			buffer.InsertWithTagsByName (ref insertIter, "Strikethrough", "strikethrough");
			buffer.Insert (ref insertIter, ", ");
			buffer.InsertWithTagsByName (ref insertIter, "underline", "underline");
			buffer.Insert (ref insertIter, ", ");
			buffer.InsertWithTagsByName (ref insertIter, "double underline", "double_underline");
			buffer.Insert (ref insertIter, ", ");
			buffer.InsertWithTagsByName (ref insertIter, "superscript", "superscript");
		        buffer.Insert (ref insertIter, ", and ");
			buffer.InsertWithTagsByName (ref insertIter, "subscript", "subscript");
			buffer.Insert (ref insertIter, " are all supported.\n\n");

			buffer.InsertWithTagsByName (ref insertIter, "Images. ", "heading");

			buffer.Insert (ref insertIter, "The buffer can have images in it: ");

			buffer.InsertPixbuf (ref insertIter, pixbuf);
			buffer.InsertPixbuf (ref insertIter, pixbuf);
			buffer.InsertPixbuf (ref insertIter, pixbuf);
			buffer.Insert (ref insertIter, " for example.\n\n");

			buffer.InsertWithTagsByName (ref insertIter, "Spacing. ", "heading");

			buffer.Insert (ref insertIter, "You can adjust the amount of space before each line.\n");
			buffer.InsertWithTagsByName (ref insertIter, "This line has a whole lot of space before it.\n",
						     "big_gap_before_line", "wide_margins");
			buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n",
						     "big_gap_after_line", "wide_margins");

			buffer.InsertWithTagsByName (ref insertIter, "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n",
						     "double_spaced_line", "wide_margins");

			buffer.Insert (ref insertIter, "Also note that those lines have extra-wide margins.\n\n");

			buffer.InsertWithTagsByName (ref insertIter, "Editability. ", "heading");

			buffer.InsertWithTagsByName (ref insertIter, "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n",
						     "not_editable");

			buffer.InsertWithTagsByName (ref insertIter, "Wrapping. ", "heading");

			buffer.Insert (ref insertIter, "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n");

			buffer.InsertWithTagsByName (ref insertIter,  "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n",
						     "char_wrap");

			buffer.InsertWithTagsByName (ref insertIter, "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n",
						     "no_wrap");

			buffer.InsertWithTagsByName (ref insertIter, "Justification. ", "heading");


			buffer.InsertWithTagsByName (ref insertIter, "\nThis line has center justification.\n", "center");

			buffer.InsertWithTagsByName (ref insertIter, "This line has right justification.\n", "right_justify");

			buffer.InsertWithTagsByName (ref insertIter, "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n",
						     "wide_margins");

			buffer.InsertWithTagsByName (ref insertIter, "Internationalization. ", "heading");

			buffer.Insert (ref insertIter, "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\u00fcd) Gr\u00fc\u00df Gott\nGreek (\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac) \u0393\u03b5\u03b9\u03ac \u03c3\u03b1\u03c2\nHebrew	\u05e9\u05dc\u05d5\u05dd\nJapanese (\u65e5\u672c\u8a9e)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n");

			buffer.Insert (ref insertIter, "Here's a word-wrapped quote in a right-to-left language:\n");
			buffer.InsertWithTagsByName (ref insertIter,  "\u0648\u0642\u062f \u0628\u062f\u0623 \u062b\u0644\u0627\u062b \u0645\u0646 \u0623\u0643\u062b\u0631 \u0627\u0644\u0645\u0624\u0633\u0633\u0627\u062a \u062a\u0642\u062f\u0645\u0627 \u0641\u064a \u0634\u0628\u0643\u0629 \u0627\u0643\u0633\u064a\u0648\u0646 \u0628\u0631\u0627\u0645\u062c\u0647\u0627 \u0643\u0645\u0646\u0638\u0645\u0627\u062a \u0644\u0627 \u062a\u0633\u0639\u0649 \u0644\u0644\u0631\u0628\u062d\u060c \u062b\u0645 \u062a\u062d\u0648\u0644\u062a \u0641\u064a \u0627\u0644\u0633\u0646\u0648\u0627\u062a \u0627\u0644\u062e\u0645\u0633 \u0627\u0644\u0645\u0627\u0636\u064a\u0629 \u0625\u0644\u0649 \u0645\u0624\u0633\u0633\u0627\u062a \u0645\u0627\u0644\u064a\u0629 \u0645\u0646\u0638\u0645\u0629\u060c \u0648\u0628\u0627\u062a\u062a \u062c\u0632\u0621\u0627 \u0645\u0646 \u0627\u0644\u0646\u0638\u0627\u0645 \u0627\u0644\u0645\u0627\u0644\u064a \u0641\u064a \u0628\u0644\u062f\u0627\u0646\u0647\u0627\u060c \u0648\u0644\u0643\u0646\u0647\u0627 \u062a\u062a\u062e\u0635\u0635 \u0641\u064a \u062e\u062f\u0645\u0629 \u0642\u0637\u0627\u0639 \u0627\u0644\u0645\u0634\u0631\u0648\u0639\u0627\u062a \u0627\u0644\u0635\u063a\u064a\u0631\u0629\u002e \u0648\u0623\u062d\u062f \u0623\u0643\u062b\u0631 \u0647\u0630\u0647 \u0627\u0644\u0645\u0624\u0633\u0633\u0627\u062a \u0646\u062c\u0627\u062d\u0627 \u0647\u0648 \u00bb\u0628\u0627\u0646\u0643\u0648\u0633\u0648\u0644\u00ab \u0641\u064a \u0628\u0648\u0644\u064a\u0641\u064a\u0627.\n\n", "rtl_quote");

			buffer.Insert (ref insertIter, "You can put widgets in the buffer: Here's a button: ");
			buttonAnchor = buffer.CreateChildAnchor (ref insertIter);
			buffer.Insert (ref insertIter, " and a menu: ");
		        menuAnchor = buffer.CreateChildAnchor (ref insertIter);
			buffer.Insert (ref insertIter, " and a scale: ");
			scaleAnchor = buffer.CreateChildAnchor (ref insertIter);
			buffer.Insert (ref insertIter, " and an animation: ");
			animationAnchor	= buffer.CreateChildAnchor (ref insertIter);
			buffer.Insert (ref insertIter, " finally a text entry: ");
			entryAnchor = buffer.CreateChildAnchor (ref insertIter);
			buffer.Insert (ref insertIter, ".\n");

 			buffer.Insert (ref insertIter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text (doesn't work in GTK 2, but planned), tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...");

			buffer.ApplyTag ("word_wrap", buffer.StartIter, buffer.EndIter);
		}
Beispiel #5
0
        private void InsertTextTable(TextBuffer buffer)
        {
            Pixbuf pixbuf2 = MainClass.Tools.GetIconFromStock("file-ms.png",IconSize.Menu);

            TextIter insertIter = buffer.StartIter;

            List<Feature> listDif = MainClass.LicencesSystem.GetUserDifferent(featureLicence);

            if(listDif!= null){
                foreach(Feature ftv in listDif){
                    buffer.Insert (ref insertIter," ");
                    buffer.InsertPixbuf (ref insertIter, pixbuf2);
                    buffer.Insert (ref insertIter, String.Format(" {0} \n", ftv.Name));
                }
            }
            buffer.ApplyTag ("word_wrap", buffer.StartIter, buffer.EndIter);
        }
Beispiel #6
0
        private void InsertTextHeader(TextBuffer buffer)
        {
            TextIter insertIter = buffer.StartIter;

            string upgradeLicence = "";
            if(featureLicence != null){
                upgradeLicence = featureLicence.Name;
            }

            buffer.InsertWithTagsByName (ref insertIter, String.Format("Moscrif {0} ",upgradeLicence), "heading");
            buffer.Insert (ref insertIter,"\n\n");

            buffer.Insert (ref insertIter,
                           String.Format("The \"{0}\" is available for Moscrif {1} license. Please purchase an upgrade to unlock this Buying Moscrif {1} License you also unlock:\n\n",featureTitle,upgradeLicence));

            buffer.ApplyTag ("word_wrap", buffer.StartIter, buffer.EndIter);
        }
Beispiel #7
0
        private void InsertTextFooter(TextBuffer buffer)
        {
            TextIter insertIter = buffer.StartIter;

            buffer.Insert (ref insertIter,"More features area avalable in Pro License. ");
            InsertLink (buffer, ref insertIter, "Buy Pro now!", 1);

            buffer.ApplyTag ("word_justification", buffer.StartIter, buffer.EndIter);
        }
	private static int DeserializeAttributes (TextBuffer buffer, int offset, XmlTextReader xmlReader, string tagSuffix)
	{
		string elementName, tagName;
		elementName = tagName = xmlReader.Name;
		DocumentTagTable tagTable = (DocumentTagTable) buffer.TagTable;
		TextIter insertAt, applyStart, applyEnd;
		insertAt = buffer.GetIterAtOffset (offset);
		TextTag tagAttributes;
		
		// Lookup Attributes tag in table, if it is not present we create one.
		tagName += ":Attributes" + tagSuffix;
		tagAttributes = tagTable.Lookup (tagName);
		if (tagAttributes == null)
			tagAttributes = tagTable.CreateDynamicTag (tagName);
		
		switch (elementName) {
		case "Type":
			DeserializeAttributesType (buffer, ref insertAt, xmlReader, tagSuffix);
			break;
		case "TypeSignature":
			DeserializeAttributesTypeSignature (buffer, ref insertAt, xmlReader, tagSuffix);
			break;
		case "Member":
			DeserializeAttributesMember (buffer, ref insertAt, xmlReader, tagSuffix);
			break;
		case "MemberSignature":
			DeserializeAttributesMemberSignature (buffer, ref insertAt, xmlReader, tagSuffix);
			break;
		default:
			DeserializeAttributesNone (buffer, ref insertAt, xmlReader, tagSuffix);
			break;
		}
		
		applyStart = buffer.GetIterAtOffset (offset);
		applyEnd = buffer.GetIterAtOffset (insertAt.Offset);
		buffer.ApplyTag (tagAttributes, applyStart, applyEnd);
		
		#if DEBUG
		Console.WriteLine ("Attributes: {0} Start: {1} End: {2}", tagName, offset, insertAt.Offset);
		#endif
		
		return insertAt.Offset;
	}
	private static int InsertEndElement (TextBuffer buffer, int offset, Stack stack, ref int depth)
	{
		TextIter insertAt, applyStart, applyEnd;
		TagStart tagStart = (TagStart) stack.Pop ();
		string suffix =  '#' + depth.ToString ();
		
		#if DEBUG
		Console.WriteLine ("Element: {0}, End: {1}", tagStart.Tag.Name, offset);
		#endif
		
		if (((DocumentTag) tagStart.Tag).IsEditable) {
			if (tagStart.Start + 1 == offset)
				offset = DocumentUtils.AddStub (buffer, offset, "To be added test", suffix);
			
			insertAt = buffer.GetIterAtOffset (offset);
			buffer.Insert (ref insertAt, "]");
			offset += 1;
		} else if (tagStart.Start == offset)
			offset = DocumentUtils.AddPaddingEmpty (buffer, offset, suffix);
		
		applyStart = buffer.GetIterAtOffset (tagStart.Start);
		applyEnd = buffer.GetIterAtOffset (offset);
		buffer.ApplyTag (tagStart.Tag, applyStart, applyEnd);
		offset = FormatEnd (buffer, offset, suffix, tagStart.Name);
		depth--;
		
		#if DEBUG
		Console.WriteLine ("Applied: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
		#endif
		
		// Padding between tag regions
		suffix = "#" + depth;
		offset = DocumentUtils.AddPadding (buffer, offset, suffix);
		
		return offset;
	}
	private static int InsertStartElement (TextBuffer buffer, int offset, XmlTextReader xmlReader, Stack stack, ref int depth, ref int count)
	{
		string elementName = xmlReader.Name;
		string suffix = String.Empty;
		DocumentTagTable tagTable = (DocumentTagTable) buffer.TagTable;
		bool emptyElement = xmlReader.IsEmptyElement;
		bool isDynamic = DocumentTagTable.IsDynamic (elementName);
		TextIter insertAt, applyStart, applyEnd;
		depth++;
		
		// We define a suffix so each dynamic tag has an unique name.
		// Suffix has format: #{depth level}
		if (isDynamic)
			suffix = "#" + depth;
		
		// We add any needed string to give format to the document.
		offset = FormatStart (buffer, offset, suffix, elementName);
		
		TagStart tagStart = new TagStart ();
		tagStart.Start = offset;
		tagStart.Name = elementName;
		
		// We first lookup the tag name, if the element is dynamic, we can
		// have three scenarios.
		// 1) The tag is not in the table: So we create it in the spot.
		// 2) Tag is in table but it priority is wrong: We created a new
		// dynamic tag with an extra suffix. Format #{depth level}.{count}
		// 3) Tag is in table with right priority: We reuse it and we don't
		// create a new dymamic tag.
		tagStart.Tag = tagTable.Lookup (elementName + suffix);
		if (isDynamic && tagStart.Tag == null)
			tagStart.Tag = tagTable.CreateDynamicTag (elementName + suffix);
		else if (isDynamic && tagStart.Tag != null &&  tagStart.Tag.Priority < ((TagStart) stack.Peek ()).Tag.Priority) {
			suffix += "." + count;
			tagStart.Tag = tagTable.CreateDynamicTag (elementName + suffix);
			count++;
		}
		
		#if DEBUG
		try {
			Console.WriteLine ("Element: {0} Start: {1}", tagStart.Tag.Name, tagStart.Start);
		} catch (NullReferenceException) {
			Console.WriteLine ("Error: Missing {0} element", xmlReader.Name);
			Environment.Exit (1);
		}
		#endif
		
		// If element has attributes we have to get them and deserialize them.
		if (xmlReader.HasAttributes)
			offset = DeserializeAttributes (buffer, offset, xmlReader, suffix);
		
		// Special case when an elment is empty.
		// Case A: If element is editable a string stub is inserted to allow edition.
		// Case B: If element is not editable then a padding is inserted to handle
		// TextTag behaviour in which zero length ranges are lost.
		if (emptyElement) {
			if (((DocumentTag) tagStart.Tag).IsEditable) {
				insertAt = buffer.GetIterAtOffset (offset);
				buffer.Insert (ref insertAt, "[");
				offset += 1;
				
				offset = DocumentUtils.AddStub (buffer, offset, "Click to Add Documentation", suffix);
				
				insertAt = buffer.GetIterAtOffset (offset);
				buffer.Insert (ref insertAt, "]");
				offset += 1;
			} else
				offset = DocumentUtils.AddPaddingEmpty (buffer, offset, suffix);
			
			applyStart = buffer.GetIterAtOffset (tagStart.Start);
			applyEnd = buffer.GetIterAtOffset (offset);
			buffer.ApplyTag (tagStart.Tag, applyStart, applyEnd);
			offset = FormatEnd (buffer, offset, suffix, elementName);
			
			// Padding between tag regions
			offset = DocumentUtils.AddPadding (buffer, offset, suffix);
			depth--;
			
			#if DEBUG
			Console.WriteLine ("Empty Element: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
			#endif
		} else {
			stack.Push (tagStart);
			
			if (((DocumentTag) tagStart.Tag).IsEditable) {
				insertAt = buffer.GetIterAtOffset (offset);
				buffer.Insert (ref insertAt, "[");
				offset += 1;
			}
		}
		
		return offset;
	}