Beispiel #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;
 }
Beispiel #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();
             }
         }
     }
 }
 //
 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;
 }
 //
 private Node ChildNodeFromPoint (Node Parent_Node, int x, int y, CaretLocation result)
 {
     Node node = null;
     try
     {
         bool done = false;
         int i = 0;
         NodesList childrenNodes = null;
         childrenNodes = Parent_Node.GetChildrenNodes ();
         int count = 0;
         if (childrenNodes == null)
         {
             return node;
         }
         count = childrenNodes.Count;
         while (!done && (i < count))
         {
             Node child = null;
             child = childrenNodes.Get (i);
             if ((child != null) && child.isVisible)
             {
                 if ((x >= child.box.X) && (x <= (child.box.X + (child.box.Width / 2))))
                 {
                     node = child;
                     result.pos = CaretPosition.Left;
                     done = true;
                 }
                 else if ((x >= (child.box.X + (child.box.Width / 2))) && (x <= (child.box.X + child.box.Width)))
                 {
                     node = child;
                     result.pos = CaretPosition.Right;
                     done = true;
                 }
             }
             i++;
         }
         if ((!done && (Parent_Node.lastChild != null)) && Parent_Node.lastChild.isVisible)
         {
             node = Parent_Node.lastChild;
         }
     }
     catch
     {
     }
     return node;
 }
 //
 private void PropogateAttributes (Node trNode1, Node trNode2)
 {
     try
     {
         if ((trNode1.type_.type != ElementType.Mtr) ||
             (trNode2.type_.type != ElementType.Mtr))
         {
             return;
         }
         NodesList list1 = trNode1.GetChildrenNodes ();
         NodesList list2 = trNode2.GetChildrenNodes ();
         if (list1.Count != list2.Count)
         {
             return;
         }
         for (int i = 0; i < list1.Count; i++)
         {
             if (i < list2.Count)
             {
                 Node child1 = list1.Get (i);
                 Node child2 = list2.Get (i);
                 if (child1.attrs != null)
                 {
                     child1.attrs.Reset ();
                     try
                     {
                         for (int j = 0; j < child1.attrs.Count; j++)
                         {
                             Nodes.Attribute attr1 = child1.attrs.Next ();
                             Nodes.Attribute attr2 = new Nodes.Attribute (attr1.name, attr1.val, attr1.ns);
                             if (child2.attrs == null)
                             {
                                 child2.attrs = new AttributeList ();
                             }
                             child2.attrs.Add (attr2);
                         }
                     }
                     catch
                     {
                     }
                     child1.attrs.Reset ();
                     if (child2.attrs != null)
                     {
                         child2.attrs.Reset ();
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
 //
 private bool IsEmptyRow (Node trNode)
 {
     bool r = false;
     try
     {
         if (trNode.type_.type != ElementType.Mtr)
         {
             return r;
         }
         NodesList list = trNode.GetChildrenNodes ();
         int i = 0;
         while ((i < list.Count) && this.IsEmptyCell (list.Get (i)))
         {
             i++;
         }
         if (i == list.Count)
         {
             r = true;
         }
     }
     catch
     {
     }
     return r;
 }
Beispiel #7
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();
 }
        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);
            }
        }
Beispiel #9
0
 public override void Draw(Node node, PaintMode printMode, Color color)
 {
     if ((printMode == PaintMode.BACKGROUND))
     {
         base.painter_.FillRectangle(node);
     }
     else if ((printMode == PaintMode.FOREGROUND))
     {
         if (node.NotBlack())
         {
             color = node.style_.color;
         }
         
         if (this.attrs != null)
         {
             if (this.attrs.open.Length > 0)
             {
                 base.painter_.DrawFence(node, this.attrs.open, color);
             }
             if (this.attrs.close.Length > 0)
             {
                 int x = node.box.X;
                 int w = node.box.Width;
                 try
                 {
                     node.box.X = (x + w) - this.closeWidth;
                     node.box.Width = this.closeWidth;
                     base.painter_.DrawFence(node, this.attrs.close, color);
                 }
                 catch
                 {
                 }
                 node.box.X = x;
                 node.box.Width = w;
             }
         }
         int b = base.painter_.MeasureBaseline(node, node.style_, ",");
         NodesList nodesList = node.GetChildrenNodes();
         if (nodesList != null)
         {
             Node next = nodesList.Next();
             if (next != null)
             {
                 next = nodesList.Next();
             }
             while (next != null)
             {
                 int xoff = 2;
                 try
                 {
                     xoff = this.leading / 3;
                 }
                 catch
                 {
                 }
                 if (this.Separator(next) != "")
                 {
                     base.painter_.DrawString(next, next.style_, (next.box.X - this.SeparatorWidth(next)) + xoff, (base.rect.y + base.rect.baseline) - b, 0, 0, this.Separator(next), color);
                 }
                 next = nodesList.Next();
             }
         }
     }
 }