Example #1
0
        public Node NodeAtPoint(Point p, CaretLocation result)
        {
            NodesList list = GetChildrenNodes();

            for (Node n = list.Next(); n != null; n = list.Next())
            {
                if (n.GetCaretPos(p) != CaretPosition.None)
                {
                    return(n.NodeAtPoint(p, result));
                }
            }

            result.pos = GetCaretPos(p);
            if (result.pos == CaretPosition.None)
            {
                return(null);
            }
            return(this);
        }
Example #2
0
        public Node NodeAtPoint(Point p, CaretLocation result)
        {
            NodesList list = GetChildrenNodes();
            for (Node n = list.Next(); n != null; n = list.Next())
            {
                if (n.GetCaretPos(p) != CaretPosition.None)
                {
                    return n.NodeAtPoint(p, result);
                }
            }

            result.pos = GetCaretPos(p);
            if (result.pos == CaretPosition.None)
            {
                return null;
            }
            return this;
        }
Example #3
0
 //
 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;
 }
Example #4
0
        //
        public bool SelectionTo (int x, int y)
        {
            try
            {
                Node mcell;
                Node lastSelected = this.MultiSelectNode();
                Point point = new Point(x, y);
                CaretLocation location = new CaretLocation();
                try
                {
                    if (this.rootNode_ != null)
                    {
                        if (point.X < 0)
                        {
                            point.X = 0;
                        }
                        if (point.Y < 0)
                        {
                            point.Y = 0;
                        }
                        if (point.X > (this.rootNode_.box.X + this.rootNode_.box.Width))
                        {
                            point.X = (this.rootNode_.box.X + this.rootNode_.box.Width) - 1;
                        }
                        if (point.Y > (this.rootNode_.box.Y + this.rootNode_.box.Height))
                        {
                            point.Y = (this.rootNode_.box.Y + this.rootNode_.box.Height) - 1;
                        }
                    }
                }
                catch
                {
                }
                Node nodeatPoint = this.rootNode_.NodeAtPoint(point, location);
                if (((nodeatPoint.type_.type == ElementType.Entity) && (nodeatPoint.parent_ != null)) &&
                    ((nodeatPoint.parent_.type_.type == ElementType.Mi) ||
                     (nodeatPoint.parent_.type_.type == ElementType.Mo)))
                {
                    nodeatPoint = nodeatPoint.parent_;
                }
                if ((nodeatPoint == null) || (lastSelected == null))
                {
                    return false;
                }
                if (nodeatPoint.level == 0)
                {
                    return false;
                }
                if (((nodeatPoint.level == 1)) &&
                    ((nodeatPoint.type_.type == ElementType.Mtable) && (nodeatPoint.Class == "nugentoplevel")))
                {
                    return false;
                }
                if (this.IsToplevelRowCell(this.multiSelectNode))
                {
                    bool top = false;
                    if ((nodeatPoint.level == 2) && (nodeatPoint.type_.type == ElementType.Mtr))
                    {
                        if ((nodeatPoint.firstChild != null) && (nodeatPoint.firstChild.type_.type == ElementType.Mtd))
                        {
                            Node cell = nodeatPoint.firstChild;
                            Node target = this.ChildNodeFromPoint(cell, x, y, location);
                            if (target != null)
                            {
                                nodeatPoint = target;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else if ((nodeatPoint.level == 3) && (nodeatPoint.type_.type == ElementType.Mtd))
                    {
                        Node cell = nodeatPoint;
                        Node target = this.ChildNodeFromPoint(cell, point.X, point.Y, location);
                        if (target != null)
                        {
                            nodeatPoint = target;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    
                    mcell = nodeatPoint;
                    if (mcell.level > 4)
                    {
                        while (mcell.level > 4)
                        {
                            mcell = mcell.parent_;
                        }
                    }
                    if ((((mcell.level == 4) && mcell.isVisible) &&
                         ((mcell.level == this.multiSelectNode.level) && this.IsToplevelRowCell(mcell))) &&
                        (mcell.parent_ != this.multiSelectNode.parent_))
                    {
                        top = true;
                        nodeatPoint = mcell;
                    }
                    if (top)
                    {
                        try
                        {
                            bool atom = false;
                            if ((nodeatPoint.IsAtom() && (nodeatPoint.literalText != null)) &&
                                (nodeatPoint.literalText.Length > 1))
                            {
                                if (point.X > (nodeatPoint.box.X + nodeatPoint.box.Width))
                                {
                                    this.SelectNode(nodeatPoint, true);
                                }
                                else
                                {
                                    this.SelectNode(nodeatPoint, false);
                                    this.selectedNode.MarkFromPoint(point);
                                    this.selectedNode.LiteralStart = this.selectedNode.LiteralStart;
                                }
                                atom = true;
                            }
                            else
                            {
                                if (location.pos == CaretPosition.Right)
                                {
                                    if ((nodeatPoint.nextSibling != null) && nodeatPoint.nextSibling.isVisible)
                                    {
                                        this.SelectNode(nodeatPoint.nextSibling, false);
                                    }
                                    else
                                    {
                                        this.SelectNode(nodeatPoint, true);
                                    }
                                }
                                else
                                {
                                    this.SelectNode(nodeatPoint, false);
                                }
                                atom = true;
                            }
                            if (!atom)
                            {
                                return false;
                            }

                            return true;
                        }
                        catch
                        {
                        }
                        return false;
                    }
                }
                
                if (((nodeatPoint.parent_ == null) || (lastSelected.parent_ == null)) || (lastSelected.parent_ != nodeatPoint.parent_))
                {
                    Node n = nodeatPoint;
                    while ((n.parent_ != null) && (n.parent_ != lastSelected.parent_))
                    {
                        n = n.parent_;
                    }
                    if ((n.parent_ == lastSelected.parent_) && n.isVisible)
                    {
                        nodeatPoint = n;
                        if ((point.X >= (nodeatPoint.box.X + (nodeatPoint.box.Width/2))) &&
                            (point.X <= (nodeatPoint.box.X + nodeatPoint.box.Width)))
                        {
                            location.pos = CaretPosition.Right;
                        }
                        else
                        {
                            location.pos = CaretPosition.Left;
                        }
                    }
                }
                if (((nodeatPoint.parent_ != null) && (lastSelected.parent_ != null)) && (lastSelected.parent_ == nodeatPoint.parent_))
                {
                    if ((nodeatPoint.parent_.type_.minChilds > 1) && (nodeatPoint != lastSelected))
                    {
                        return false;
                    }
                    if (!nodeatPoint.isVisible)
                    {
                        return false;
                    }
                    
                    if ((nodeatPoint.IsAtom() && (nodeatPoint.literalText != null)) && (nodeatPoint.literalText.Length > 1))
                    {
                        this.SelectNode(nodeatPoint, false);
                        this.selectedNode.MarkFromPoint(point);
                        return true;
                    }
                    if (location.pos == CaretPosition.Right)
                    {
                        if (nodeatPoint.nextSibling != null)
                        {
                            this.SelectNode(nodeatPoint, false);
                            return this.SelectionRight();
                        }
                        this.SelectNode(nodeatPoint, true);
                        return true;
                    }
                    this.SelectNode(nodeatPoint, false);
                    return true;
                }

                return false;
            }
            catch
            {
            }
            return false;
        }
Example #5
0
        //
        public bool SelectNode (int x, int y)
        {
            this.HasSelection = false;
            Node foundNode = null;
            try
            {
                Point point = new Point (x, y);
                CaretLocation caretLocation = new CaretLocation ();
                try
                {
                    if (this.rootNode_ != null)
                    {
                        if (point.X < 0)
                        {
                            point.X = 0;
                        }
                        if (point.Y < 0)
                        {
                            point.Y = 0;
                        }
                        if (point.X > (this.rootNode_.box.X + this.rootNode_.box.Width))
                        {
                            point.X = (this.rootNode_.box.X + this.rootNode_.box.Width) - 1;
                        }
                        if (point.Y > (this.rootNode_.box.Y + this.rootNode_.box.Height))
                        {
                            point.Y = (this.rootNode_.box.Y + this.rootNode_.box.Height) - 1;
                        }
                    }
                }
                catch
                {
                }
                foundNode = this.rootNode_.NodeAtPoint (point, caretLocation);
                if ((foundNode == null) || !foundNode.isVisible)
                {
                    return false;
                }

                if (((foundNode.type_.type == ElementType.Entity) && (foundNode.parent_ != null)) &&
                    ((foundNode.parent_.type_.type == ElementType.Mi) ||
                     (foundNode.parent_.type_.type == ElementType.Mo)))
                {
                    foundNode = foundNode.parent_;
                }
                
                if ((foundNode.level == 0))
                {
                    return false;
                }

                if (((foundNode.level == 1)) &&
                    ((foundNode.type_.type == ElementType.Mtable) && (foundNode.Class == "nugentoplevel")))
                {
                    return false;
                }
                
                if (foundNode.skip)
                {
                    try
                    {
                        if ((foundNode.type_.type == ElementType.Mrow) && (foundNode.firstChild == null))
                        {
                            if (caretLocation.pos == CaretPosition.Right)
                            {
                                this.SelectNode (foundNode, true);
                            }
                            else
                            {
                                this.SelectNode (foundNode, false);
                            }
                            return true;
                        }
                        if (foundNode.type_.type == ElementType.Mtr)
                        {
                            if ((foundNode.firstChild != null) &&
                                (foundNode.firstChild.type_.type == ElementType.Mtd))
                            {
                                Node child = this.ChildNodeFromPoint (foundNode, point.X, point.Y, caretLocation);
                                if ((child != null) && (child.firstChild != null))
                                {
                                    Node target = this.ChildNodeFromPoint (child, point.X, point.Y, caretLocation);
                                    if (target != null)
                                    {
                                        if (caretLocation.pos == CaretPosition.Right)
                                        {
                                            if ((target.nextSibling != null) && target.nextSibling.isVisible)
                                            {
                                                this.SelectNode (target.nextSibling, false);
                                                return true;
                                            }
                                            this.SelectNode (target, true);
                                            return true;
                                        }
                                        this.SelectNode (target, false);
                                        return true;
                                    }
                                }
                            }
                            return false;
                        }
                        if (foundNode.type_.type == ElementType.Mtd)
                        {
                            if ((foundNode.firstChild != null) && foundNode.firstChild.isVisible)
                            {
                                Node cell = foundNode;
                                if ((cell != null) && (cell.firstChild != null))
                                {
                                    Node target = this.ChildNodeFromPoint (cell, point.X, point.Y, caretLocation);
                                    if (target != null)
                                    {
                                        if (caretLocation.pos == CaretPosition.Right)
                                        {
                                            if ((target.nextSibling != null) && target.nextSibling.isVisible)
                                            {
                                                this.SelectNode (target.nextSibling, false);
                                                return true;
                                            }
                                            this.SelectNode (target, true);
                                            return true;
                                        }
                                        this.SelectNode (target, false);
                                        return true;
                                    }
                                }
                            }
                            return false;
                        }
                    }
                    catch
                    {
                    }
                    if ((foundNode.level == 0))
                    {
                        return false;
                    }
                    this.SelectNode (foundNode, false);
                    return this.GoRight ();
                }
                if (foundNode.isGlyph)
                {
                    if ((foundNode.level == 0))
                    {
                        return false;
                    }
                    this.SelectNode (foundNode, false);
                    return this.GoLeft ();
                }
                if ((foundNode.IsAtom() && (foundNode.literalText != null)) && (foundNode.literalText.Length > 1))
                {
                    this.SelectNode (foundNode, false);
                    this.selectedNode.MarkFromPoint (point);
                    this.selectedNode.LiteralStart = this.selectedNode.LiteralStart;
                    return true;
                }
                
                if (caretLocation.pos == CaretPosition.Right)
                {
                    if ((foundNode.level == 0))
                    {
                        return false;
                    }
                    if (foundNode.nextSibling != null)
                    {
                        this.SelectNode (foundNode, false);
                        return this.GoRight ();
                    }
                    this.SelectNode (foundNode, true);
                }
                else
                {
                    if ((foundNode.level == 0))
                    {
                        return false;
                    }
                    this.SelectNode (foundNode, false);
                }
                return true;
            }
            catch
            {
            }
            
            return false;
        }