Ejemplo n.º 1
0
 private Node create(Node node, Node selectedNode, Node lastSelectedNode)
 {
     Node n = new Node();
     
     n.tagDeleted = node.tagDeleted;
     n.tokenType = node.tokenType;
     n.xmlTagName = node.xmlTagName;
     n.namespaceURI = node.namespaceURI;
     n.isVisible = node.isVisible;
     n.isGlyph = node.isGlyph;
     n.skip = node.skip;
     
     n.literalText = node.literalText;
     n.literalCaret = node.literalCaret;
     n.literalStart = node.literalStart;
     n.yOffset = node.yOffset;
     n.displayStyle = node.displayStyle;
     
     n.glyph = node.glyph;
     
     n.scriptLevel_ = node.scriptLevel_;
     
     n.type_ = node.type_;
     if (node.attrs != null)
     {
         n.attrs = new AttributeList();
         node.attrs.CopyTo(n.attrs);
     }
     n.FontStyle = node.FontStyle;
     if (node.style_ != null)
     {
         n.style_ = new StyleAttributes();
         node.style_.CopyTo(n.style_);
     }
     if (node == selectedNode)
     {
         this.selected_ = n;
     }
     if (node == lastSelectedNode)
     {
         this.lastSel_ = n;
     }
     if (node.HasChildren())
     {
         NodesList list = node.GetChildrenNodes();
         int count = list.Count;
         for (int i = 0; i < count; i++)
         {
             Node c = list.Get(i);
             Node child = this.create(c, selectedNode, lastSelectedNode);
             if (child != null)
             {
                 n.AdoptChild(child);
             }
         }
     }
     return n;
 }
Ejemplo n.º 2
0
 public void FillBackground(Node node)
 {
     if (node.HasChildren())
     {
         NodesList nodesList = node.GetChildrenNodes();
         Node n = nodesList.Next();
         int x = 0;
         int y = 0;
         int w = 0;
         int h = 0;
         while (n != null)
         {
             if (n.NotOnWhite())
             {
                 x = n.box.X;
                 y = n.box.Y;
                 w = n.box.Width;
                 h = n.box.Height;
                 int count = 0;
                 while (((n.nextSibling != null) && n.nextSibling.NotOnWhite()) && (n.nextSibling.Background == n.Background))
                 {
                     n = n.nextSibling;
                     if (n.box.Y < y)
                     {
                         h += y - n.box.Y;
                         y = n.box.Y;
                     }
                     if ((n.box.X + n.box.Width) > (x + w))
                     {
                         w = (n.box.X + n.box.Width) - x;
                     }
                     if ((n.box.Y + n.box.Height) > (y + h))
                     {
                         h = (n.box.Y + n.box.Height) - y;
                     }
                     count++;
                 }
                 if (count > 0)
                 {
                     this.FillRectangle(x, y, w, h, n.Background);
                 }
             }
             if (n != null)
             {
                 n = nodesList.Next();
             }
         }
     }
 }
Ejemplo n.º 3
0
 //
 private bool IsEmptyCell (Node node)
 {
     bool r = false;
     try
     {
         if (node.type_.type != ElementType.Mtd)
         {
             return r;
         }
         if (node.HasChildren ())
         {
             if (((node.numChildren == 1) && (node.firstChild.type_.type == ElementType.Mrow)) &&
                 (node.firstChild.numChildren == 0))
             {
                 r = true;
             }
             return r;
         }
         return true;
     }
     catch
     {
         return r;
     }
 }
Ejemplo n.º 4
0
 //
 private void TagAsDeleted (Node node)
 {
     if (node.HasChildren ())
     {
         NodesList list = node.GetChildrenNodes ();
         for (int i = 0; i < list.Count; i++)
         {
             Node n = list.Get (i);
             if (n != null)
             {
                 this.TagAsDeleted (n);
             }
         }
     }
     node.tagDeleted = true;
     node = null;
 }
Ejemplo n.º 5
0
 //
 private bool EnterPressed_NeedSplit (bool splitCell)
 {
     bool isTop = false;
     try
     {
         Node cur = this.GetCurrentlySelectedNode ();
         if (((cur == null)) || (cur.type_.type == ElementType.Math))
         {
             return isTop;
         }
         try
         {
             bool isLast = false;
             bool isfirst = false;
             Node td = null;
             Node c = cur;
             bool isMath = false;
             while (((c.parent_ != null) && !isMath) && (c.type_.type != ElementType.Mtd))
             {
                 if (c.type_.type == ElementType.Math)
                 {
                     isMath = true;
                     continue;
                 }
                 td = c;
                 c = c.parent_;
             }
             if ((c != null) && (c.type_.type == ElementType.Mtd))
             {
                 Node cell = c;
                 if (cell.nextSibling == null)
                 {
                     isLast = true;
                 }
                 if (((cell.nextSibling != null) && (cell.prevSibling == null)) &&
                     ((cell.firstChild == cur) && (cur.InternalMark == 0)))
                 {
                     isfirst = true;
                 }
                 if ((cell.parent_ != null) && (cell.parent_.type_.type == ElementType.Mtr))
                 {
                     Node row = cell.parent_;
                     int numCols = row.numChildren;
                     string xml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">";
                     xml = xml + "<mtable columnalign=\"left\">";
                     xml = xml + "<mtr>";
                     for (int i = 0; i < numCols; i++)
                     {
                         if (i == 0)
                         {
                             xml = xml + "<mtd nugenCursor=''/>";
                         }
                         else
                         {
                             xml = xml + "<mtd><mrow/></mtd>";
                         }
                     }
                     xml = xml + "</mtr>";
                     xml = xml + "</mtable>";
                     xml = xml + "</math>";
                     XmlDocument doc = new XmlDocument ();
                     doc.LoadXml (xml);
                     XmlNode topnode = doc.DocumentElement.FirstChild;
                     Node newNode = new Node ();
                     Node newSelected = newNode.Parse (topnode, this.types_, this.entityManager, true, null);
                     Node toSel = null;
                     if (newNode.HasChildren ())
                     {
                         newNode = newNode.firstChild;
                     }
                     if (newNode.type_.type != ElementType.Mtr)
                     {
                         return isTop;
                     }
                     if (isfirst)
                     {
                         row.PrependNode (newNode);
                         this.PropogateAttributes (row, newNode);
                         if ((newSelected.type_.type == ElementType.Mtd) && (newSelected.numChildren == 0))
                         {
                             newSelected.AdoptChild (this.CreateRow ());
                         }
                         this.SelectNode (cur, false);
                         return isTop;
                     }
                     row.AppendNode (newNode);
                     this.PropogateAttributes (row, newNode);
                     if (newSelected == null)
                     {
                         return isTop;
                     }
                     if (splitCell && isLast)
                     {
                         if (td != null)
                         {
                             Node cel = td;
                             toSel = newSelected;
                             int num = 0;
                             if ((cel.InternalMark == 0) && (cel.prevSibling == null))
                             {
                                 Node rrow = cel.parent_;
                                 while (rrow.numChildren > 0)
                                 {
                                     this.ReParent (rrow.firstChild.parent_, newSelected, rrow.firstChild);
                                     if (num == 0)
                                     {
                                         toSel = rrow.firstChild;
                                     }
                                     num++;
                                 }
                                 if ((rrow.type_.type == ElementType.Mtd) &&
                                     (rrow.numChildren == 0))
                                 {
                                     rrow.AdoptChild (this.CreateRow ());
                                 }
                             }
                             else
                             {
                                 bool wasSplit = false;
                                 if (cel.InternalMark == 0)
                                 {
                                     cel = cel.prevSibling;
                                 }
                                 else if (!cel.IsAppend && (cel.literalText.Length > 1))
                                 {
                                     this.CarriageReturn (cel, ref wasSplit);
                                 }
                                 while (cel.nextSibling != null)
                                 {
                                     this.ReParent (cel.nextSibling.parent_, newSelected, cel.nextSibling);
                                     if (num == 0)
                                     {
                                         toSel = cel.nextSibling;
                                     }
                                     num++;
                                 }
                             }
                         }
                         if (toSel != null)
                         {
                             this.SelectNode (toSel, false);
                             if (toSel.type_.type == ElementType.Mtd)
                             {
                                 if (toSel.firstChild != null)
                                 {
                                     this.SelectNode (toSel.firstChild, false);
                                 }
                                 else
                                 {
                                     toSel.AdoptChild (this.CreateRow ());
                                     toSel.UpdateChildrenIndices ();
                                     toSel.UpdateLevel ();
                                     this.SelectNode (toSel.firstChild, false);
                                 }
                             }
                         }
                         if (((newSelected != null) && (newSelected.type_.type == ElementType.Mtd)) &&
                             (newSelected.numChildren == 0))
                         {
                             newSelected.AdoptChild (this.CreateRow ());
                             newSelected.UpdateChildrenIndices ();
                             newSelected.UpdateLevel ();
                             this.SelectNode (newSelected.firstChild, false);
                         }
                         return isTop;
                     }
                     if (newSelected.firstChild != null)
                     {
                         this.SelectNode (newSelected.firstChild, false);
                         return isTop;
                     }
                     newSelected.AdoptChild (this.CreateRow ());
                     if (newSelected.firstChild != null)
                     {
                         this.SelectNode (newSelected.firstChild, false);
                     }
                 }
                 return isTop;
             }
             this.MakeTopTable ();
             return isTop;
         }
         finally
         {
             this.SelectCell ();
             isTop = true;
         }
     }
     catch
     {
     }
     return isTop;
 }
Ejemplo n.º 6
0
 //
 public bool ApplyActionAttrs (Node node, ActionAttributes ActionAttributes, string statusLine)
 {
     try
     {
         this.OnInsert (false);
         if ((ActionAttributes.actionType == ActionType.StatusLine) ||
             (ActionAttributes.actionType == ActionType.ToolTip))
         {
             try
             {
                 if (node.HasChildren ())
                 {
                     Node first = node.firstChild;
                     if ((first != null) && (first.nextSibling != null))
                     {
                         first = first.nextSibling;
                         if (first.type_.type == ElementType.Mtext)
                         {
                             first.literalText = statusLine;
                         }
                     }
                 }
             }
             catch
             {
             }
         }
         if ((node != null) && (ActionAttributes != null))
         {
             AttributeBuilder.ApplyAttrs (node, ActionAttributes);
         }
     }
     catch
     {
     }
     return true;
 }
Ejemplo n.º 7
0
 public MActionDialog(Node node)
 {
     this.container = null;
     this.success = false;
     this.node = null;
     if (node != null)
     {
         this.node = node;
         this.attributes = AttributeBuilder.ActionAttributes(node);
         if (this.attributes == null)
         {
             this.attributes = new ActionAttributes();
         }
     }
     this.InitializeComponent();
     if (this.attributes.actionType == ActionType.StatusLine)
     {
         this.statusline.Checked = true;
         this.spinner.Enabled = false;
         this.spinner.Maximum = new decimal(1);
         this.statline.Enabled = true;
     }
     else if (this.attributes.actionType == ActionType.ToolTip)
     {
         this.tooltip.Checked = true;
         this.spinner.Enabled = false;
         this.spinner.Maximum = new decimal(1);
         this.statline.Enabled = true;
     }
     else if (this.attributes.actionType == ActionType.Highlight)
     {
         this.highlight.Checked = true;
         this.spinner.Enabled = false;
         this.spinner.Maximum = new decimal(1);
         this.statusline.Enabled = false;
         this.tooltip.Enabled = false;
         this.statline.Enabled = false;
         this.statline.Text = "";
     }
     else if (this.attributes.actionType == ActionType.Toggle)
     {
         this.toggle.Checked = true;
         this.statusline.Enabled = false;
         this.tooltip.Enabled = false;
         this.spinner.Enabled = true;
         this.spinner.Maximum = (decimal) node.numChildren;
         this.spinner.Value = (decimal) this.attributes.selection;
         this.statline.Enabled = false;
         this.statline.Text = "";
     }
     else
     {
         this.statusline.Checked = false;
         this.tooltip.Checked = false;
         this.toggle.Checked = false;
         this.highlight.Checked = false;
         this.spinner.Enabled = false;
         this.spinner.Maximum = new decimal(1);
         this.statline.Enabled = false;
         this.statline.Text = "";
     }
     if ((this.attributes.actionType == ActionType.StatusLine) || (this.attributes.actionType == ActionType.ToolTip))
     {
         string s = "";
         try
         {
             if (node.HasChildren())
             {
                 Node n = node.firstChild;
                 if ((n != null) && (n.nextSibling != null))
                 {
                     n = n.nextSibling;
                     if (n.type_.type == ElementType.Mtext)
                     {
                         s = n.literalText;
                     }
                 }
             }
         }
         catch
         {
         }
         this.statline.Text = s;
     }
 }
Ejemplo n.º 8
0
 public MTable(Node node)
 {
     this.colColSpan = 0;
     this.totalHorzFrameSpacing = 0;
     this.totalWidth = 0;
     this.minWidth = 30;
     this.totalVertFrameSpacing = 0;
     this.tableAlign = 0;
     this.rowFrameSpacing = 0;
     this.colFrameSpacing = 0;
     this.maxWidth = 0;
     this.curRow = 0;
     this.curCol = 0;
     this.selKind_ = TableCellKind.SelAll;
     this.displayStyle = false;
     this.equalRows = false;
     this.equalColumns = false;
     this.align = TableAlign.AXIS;
     this.frame = TableLineStyle.NONE;
     this.framespacing = "0.4em 0.5ex";
     this.side = Side.RIGHT;
     this.minlabelSpacing = "0.8em";
     this.colLines = new TableLineStyle[] { TableLineStyle.NONE };
     this.colSpacing = new string[] { "0.8em" };
     this.colAligns = new HAlign[] { HAlign.CENTER };
     this.rowAligns = new RowAlign[] { RowAlign.BASELINE };
     this.node_ = node;
     this.attrs = AttributeBuilder.mtableAttributes(node);
     if (this.attrs != null)
     {
         this.rowAligns = this.attrs.rowAligns;
         this.colAligns = this.attrs.colAligns;
         this.colLines = this.attrs.colLines;
         this.colSpacing = this.attrs.colSpacing;
         this.displayStyle = this.attrs.displaystyle;
         this.equalRows = this.attrs.equalRows;
         this.equalColumns = this.attrs.equalColumns;
         this.align = this.attrs.align;
         this.frame = this.attrs.frame;
         this.framespacing = this.attrs.framespacing;
         this.side = this.attrs.side;
         this.minlabelSpacing = this.attrs.minlabelspacing;
     }
     this.rows = new ArrayList();
     if (node.HasChildren())
     {
         NodesList nodesList = node.GetChildrenNodes();
         Node n = nodesList.Next();
         for (int i = 0; n != null; i++)
         {
             MRow row = this.AddRow(n, i);
             if (this.attrs != null)
             {
                 if (i < this.attrs.rowSpacing.Length)
                 {
                     row.spacing = this.attrs.rowSpacing[i];
                 }
                 else if (this.attrs.rowSpacing.Length > 0)
                 {
                     row.spacing = this.attrs.rowSpacing[this.attrs.rowSpacing.Length - 1];
                 }
                 if (i < this.attrs.rowLines.Length)
                 {
                     row.lines = this.attrs.rowLines[i];
                 }
                 else if (this.attrs.rowLines.Length > 0)
                 {
                     row.lines = this.attrs.rowLines[this.attrs.rowLines.Length - 1];
                 }
             }
             if (row.attrs != null)
             {
                 row.colAligns = row.attrs.colAligns;
                 row.align = row.attrs.align;
             }
             if (n.HasChildren())
             {
                 NodesList list = n.GetChildrenNodes();
                 Node child = list.Next();
                 int colSpan = 0;
                 if (n.type_.type == ElementType.Mlabeledtr)
                 {
                     row.isLabeled = true;
                     MCell cell = row.AddLabel(child, n.numChildren - 1);
                     if (cell.tableAttrs != null)
                     {
                         cell.rowAlign = cell.tableAttrs.rowAlign;
                         cell.columnAlign = cell.tableAttrs.columnAlign;
                         cell.columnSpan = cell.tableAttrs.columnSpan;
                         cell.rowSpan = cell.tableAttrs.rowSpan;
                     }
                     child = list.Next();
                 }
                 while (child != null)
                 {
                     MCell cell = row.AddCell(child, colSpan);
                     if (cell.tableAttrs != null)
                     {
                         cell.rowAlign = cell.tableAttrs.rowAlign;
                         cell.columnAlign = cell.tableAttrs.columnAlign;
                         cell.columnSpan = cell.tableAttrs.columnSpan;
                         cell.rowSpan = cell.tableAttrs.rowSpan;
                     }
                     child = list.Next();
                     if ((cell.tableAttrs != null) && (cell.tableAttrs.columnSpan > 1))
                     {
                         colSpan += cell.tableAttrs.columnSpan;
                         continue;
                     }
                     colSpan++;
                 }
                 if (colSpan > this.colColSpan)
                 {
                     this.colColSpan = colSpan;
                 }
             }
             n = nodesList.Next();
         }
     }
     if (this.colLines.Length < this.colColSpan)
     {
         TableLineStyle[] lines = new TableLineStyle[this.colColSpan];
         for (int colIndex = 0; colIndex < this.colColSpan; colIndex++)
         {
             if (colIndex < this.colLines.Length)
             {
                 lines[colIndex] = this.colLines[colIndex];
             }
             else if (this.colLines.Length > 0)
             {
                 lines[colIndex] = this.colLines[this.colLines.Length - 1];
             }
             else
             {
                 lines[colIndex] = TableLineStyle.NONE;
             }
         }
         this.colLines = lines;
     }
     if (this.colSpacing.Length < this.colColSpan)
     {
         string[] strings = new string[this.colColSpan];
         for (int colIndex = 0; colIndex < this.colColSpan; colIndex++)
         {
             if (colIndex < this.colSpacing.Length)
             {
                 strings[colIndex] = this.colSpacing[colIndex];
             }
             else if (this.colSpacing.Length > 0)
             {
                 strings[colIndex] = this.colSpacing[this.colSpacing.Length - 1];
             }
             else
             {
                 strings[colIndex] = "0.8em";
             }
         }
         this.colSpacing = strings;
     }
     for (int rowIndex = 0; rowIndex < this.RowCount; rowIndex++)
     {
         MRow row = this.GetRow(rowIndex);
         if (row.isLabeled && (row.cell != null))
         {
             row.cell.colSpan = this.ColCount;
         }
     }
     this.UpdateRowspan();
     this.FixVAligns();
     this.FixHAligns();
     this.UpdateUpDownTies();
 }
Ejemplo n.º 9
0
        private void tryAddMathXML (bool isInsert, string xml, bool isPaste)
        {
            string s = "";
            bool hasS = false;
            bool ok = false;
            try
            {
                if (this.HasSelection)
                {
                    xml = xml.Trim ();
                    if ((xml.IndexOf ("<math", 0, 5) != -1) &&
                        (((xml.IndexOf (" nugenCursor=\"") != -1) || (xml.IndexOf (" nugenCursor='") != -1)) ||
                         ((xml.IndexOf (" nugenCursorEnd=\"") != -1) || (xml.IndexOf (" nugenCursorEnd='") != -1))))
                    {
                        Selection selection = this.CaptureSelection ();
                        if ((selection != null))
                        {
                            XmlDocument doc = new XmlDocument ();
                            if (this.SaveToXml (doc, selection))
                            {
                                string outerxml = doc.OuterXml;
                                int startIndex = outerxml.IndexOf ("<math");
                                if (startIndex != -1)
                                {
                                    outerxml = outerxml.Substring (startIndex, outerxml.Length - startIndex);
                                    outerxml = outerxml.Trim ();
                                    if ((outerxml.IndexOf ("<math", 0, 5) != -1) &&
                                        (outerxml.Substring (outerxml.Length - 7, 7) == "</math>"))
                                    {
                                        s = outerxml;
                                        hasS = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            if (isInsert)
            {
                this.OnInsert (true);
            }

            bool emptyRow = false;
          
            Node selectedNode = this.GetCurrentlySelectedNode ();
            
            if (selectedNode == null)
            {
                return;
            }
            if (selectedNode.type_ == null)
            {
                return;
            }
            
            if (!this.IsEditable ())
            {
                return;
            }
            NodeClass nodeClass = this.GetNodeClass (selectedNode);
            selectedNode = this.GetCurrentlySelectedNode ();
            bool wasSplit = false;
            selectedNode = this.CarriageReturn (selectedNode, ref wasSplit);
            if (wasSplit)
            {
                this.SelectNode (selectedNode, false);
            }

            XmlNode xmlRoot = this.LoadXml (xml, new XmlDocument ());
            
            if (xmlRoot == null)
            {
                return;
            }
            
            if (!this.IsMultiline)
            {
                Node wasSelected = selectedNode;
                if (this.CreateTopLevelTable ())
                {
                    nodeClass = this.GetNodeClass (selectedNode);
                    selectedNode = this.GetCurrentlySelectedNode ();
                }
                else
                {
                    return;
                }
            }
            
            if ((nodeClass == NodeClass.unknown) )
            {
                return;
            }

            bool wasSelect = false;
            Node lastRow = null;
            if (!((xmlRoot == null) || !xmlRoot.HasChildNodes))
            {
                Node selRow = selectedNode;
                int count = 0;
                count = xmlRoot.ChildNodes.Count;
                int rCount = 0;
                if (((selRow.type_ != null) && (selRow.type_.type == ElementType.Mrow)) && !selRow.HasChildren())
                {
                    emptyRow = true;
                    rCount = 1;
                }
                if ((((selRow.parent_ != null)) &&
                     ((selRow.parent_.type_.maxChilds != -1) &&
                      (((selRow.parent_.numChildren - rCount) + count) >= selRow.parent_.type_.maxChilds))) ||
                    ((selRow.parent_.type_.type == ElementType.Mmultiscripts) ||
                     (selRow.parent_.type_.type == ElementType.Maction)))
                {
                    selRow = this.WrapInRowInplace(selRow);
                }

                if (selRow.IsAppend)
                {
                    Node row = selRow;
                    Node lastCell = null;
                    if (isPaste && (xmlRoot.Name == "math"))
                    {
                        Node newNode = new Node();
                        newNode.Parse(xmlRoot, this.types_, this.entityManager, true, null);
                        if ((newNode.type_ != null) && newNode.HasChildren())
                        {
                            NodesList list = newNode.GetChildrenNodes();
                            Node n = list.Next();
                            lastRow = row;
                            for (int i = 0; (row != null) && (n != null); i++)
                            {
                                row.AppendNode(n);
                                lastCell = n;
                                n = list.Next();
                                row = row.nextSibling;
                            }
                            if (lastCell != null)
                            {
                                if (lastCell.nextSibling != null)
                                {
                                    this.SelectNode(lastCell.nextSibling, false);
                                }
                                else
                                {
                                    this.SelectNode(lastCell, true);
                                }
                                wasSelect = true;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            XmlNode x = xmlRoot.ChildNodes[i];
                            Node n = new Node();
                            n.Parse(x, this.types_, this.entityManager, false, null);
                            if (n.type_ != null)
                            {
                                row.AppendNode(n);

                                lastCell = n.Parse(x, this.types_, this.entityManager, true, null);
                                if (lastCell != null)
                                {
                                    this.SelectNode(lastCell, lastCell.IsAppend);
                                    wasSelect = true;
                                    ok = true;
                                }
                                else if (i == 0)
                                {
                                    lastRow = n;
                                }
                            }
                            row = n;
                        }
                    }
                }
                else
                {
                    Node newSelectedNode = null;
                    if (isPaste && (xmlRoot.Name == "math"))
                    {
                        Node newNode = new Node();
                        newNode.Parse(xmlRoot, this.types_, this.entityManager, true, null);
                        if ((newNode.type_ != null) && newNode.HasChildren())
                        {
                            NodesList list = newNode.GetChildrenNodes();
                            Node n = list.Next();
                            for (int i = 0; (selRow != null) && (n != null); i++)
                            {
                                selRow.PrependNode(n);
                                n = list.Next();
                            }
                            this.SelectNode(selRow, false);
                            wasSelect = true;
                        }
                    }
                    else if (xmlRoot.Name == "math")
                    {
                        for (int i = 0; i < count; i++)
                        {
                            XmlNode x = xmlRoot.ChildNodes[i];
                            Node newMode = new Node();
                            newMode.Parse(x, this.types_, this.entityManager, false, null);
                            if (newMode.type_ != null)
                            {
                                selRow.PrependNode(newMode);

                                newSelectedNode =
                                    newMode.Parse(x, this.types_, this.entityManager, true, null);
                                if (newSelectedNode != null)
                                {
                                    this.SelectNode(newSelectedNode, newSelectedNode.IsAppend);
                                    ok = true;
                                    wasSelect = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            Node newNode = new Node();
                            XmlNode x = xmlRoot.ChildNodes[i];
                        
                            this.InsertFromXml(selRow, x, newNode, ref newSelectedNode, ref wasSelect);
                        }
                    }
                }

                if (!wasSelect && (lastRow != null))
                {
                    this.SelectNode(lastRow, false);
                }
                if (emptyRow)
                {
                    if (selRow == this.selectedNode)
                    {
                        this.SelectNeighbor(selRow);
                    }
                    this.Tear(selRow);
                }
            }
            
            if ((!hasS || !ok) || ((this.selectedNode.type_.type != ElementType.Mrow) || (this.selectedNode.numChildren != 0)))
            {
                return;
            }
            Node lastSelected = null;
            Node firstSelected = null;
            Node singleSelected = null;
            try
            {
                Node curPrev = null;
                Node curNext = null;
                Node cur = null;
                cur = this.selectedNode;
                cur.InternalMark = 0;
                curPrev = cur.prevSibling;
                curNext = cur.nextSibling;
                singleSelected = cur.parent_;
                
                Node targetSelected = null;
                this.tryAddMathXML (false, s, false);
                try
                {
                    targetSelected = singleSelected.GetChildrenNodes ().Get (this.selectedNode.childIndex);
                }
                catch
                {
                }
                if (targetSelected != null)
                {
                    if ((targetSelected.type_.type == ElementType.Mrow) && (targetSelected.firstChild != null))
                    {
                        cur = targetSelected;
                        lastSelected = cur.firstChild;
                        firstSelected = cur.lastChild;
                    }
                    else if (((curPrev != null) && !curPrev.tagDeleted) && ((curNext != null) && !curNext.tagDeleted))
                    {
                        lastSelected = curPrev.nextSibling;
                        firstSelected = curNext.prevSibling;
                    }
                    else if ((curPrev != null) && !curPrev.tagDeleted)
                    {
                        lastSelected = curPrev.nextSibling;
                        firstSelected = singleSelected.lastChild;
                    }
                    else if ((curNext != null) && !curNext.tagDeleted)
                    {
                        lastSelected = singleSelected.firstChild;
                        firstSelected = curNext.prevSibling;
                    }
                }
            }
            catch
            {
            }
            if ((lastSelected != null) && (firstSelected != null))
            {
                this.SelectNode (firstSelected, true);
                this.multiSelectNode = lastSelected;
                this.hasSelection = true;
            }
            else if (singleSelected != null)
            {
                this.SelectNode (singleSelected, false);
            }
        }