Exemple #1
0
        public override HitTestInfo GetHitTestInfo(IGraphics gr, int x, int y, Point pt)
        {
            ElementSelectionPoint esp = new ElementSelectionPoint(Node, TagType.EndTag);

            Line      l       = (Line)Parent;
            Rectangle rcCaret = Rectangle.Empty;

            LineItemContext ili = new LineItemContext(l.Height, l.Baseline, this, new Point(x, y));

            return(new HitTestInfo(esp, ili, false, rcCaret));
        }
        public void CutAndPaste()
        {
            XmlDocument doc1=new XmlDocument();

            doc1.LoadXml("<maindoc xmlns='ns'><elem><subelem/></elem></maindoc>");

            SelectionPoint start=new ElementSelectionPoint(doc1.DocumentElement.FirstChild, TagType.StartTag);
            SelectionPoint end=new ElementSelectionPoint(doc1.DocumentElement, TagType.EndTag);
            Selection sel=new Selection(start, end);

            sel=selectionManager.Cut(sel);
            selectionManager.Paste(sel);

            Console.WriteLine(doc1.OuterXml);

            Assert.AreEqual(0, doc1.DocumentElement.FirstChild.Attributes.Count, "Expected pasted node to have no attributes");
        }
        public void CutAndPaste()
        {
            XmlDocument doc1 = new XmlDocument();

            doc1.LoadXml("<maindoc xmlns='ns'><elem><subelem/></elem></maindoc>");

            SelectionPoint start = new ElementSelectionPoint(doc1.DocumentElement.FirstChild, TagType.StartTag);
            SelectionPoint end   = new ElementSelectionPoint(doc1.DocumentElement, TagType.EndTag);
            Selection      sel   = new Selection(start, end);

            sel = selectionManager.Cut(sel);
            selectionManager.Paste(sel);

            Console.WriteLine(doc1.OuterXml);

            Assert.AreEqual(0, doc1.DocumentElement.FirstChild.Attributes.Count, "Expected pasted node to have no attributes");
        }
Exemple #4
0
        public override HitTestInfo GetHitTestInfo(IGraphics gr, int x, int y, Point pt)
        {
            ElementSelectionPoint esp=new ElementSelectionPoint(Node, TagType.EndTag);

            Line l=(Line) Parent;
            Rectangle rcCaret=Rectangle.Empty;

            LineItemContext ili=new LineItemContext(l.Height, l.Baseline, this, new Point(x,y));
            return new HitTestInfo(esp, ili, false, rcCaret);
        }
        public void CursorLineUp()
        {
            if ( doc == null || doc.DocumentElement == null )
                return;

            CreateUndoPoint();
            Rectangle rcCaret=Rectangle.Empty;
            SelectionPoint sp=GetPreviousLineSelectionPoint(ref rcCaret);

            if ( sp == null )
                sp=new ElementSelectionPoint(doc.DocumentElement, TagType.StartTag);

            sp=selectionManager.Validate(sp);
            SetSelection(new Selection(sp));

            UpdateCaretPosition(rcCaret, false);
            EnsureCaretVisible();
        }
        public void CursorExtendDocumentEnd()
        {
            if ( doc == null || doc.DocumentElement == null )
                return;

            CreateUndoPoint();
            SelectionPoint sp=new ElementSelectionPoint(doc.DocumentElement, TagType.EndTag);
            SetSelection(new Selection(currentSelection.Start, sp));
            UpdateCaretPosition(true);
            EnsureCaretVisible();
        }
        public void CursorDocumentBegin()
        {
            if ( doc == null || doc.DocumentElement == null )
                return;

            CreateUndoPoint();
            SelectionPoint sp=new ElementSelectionPoint(doc.DocumentElement, TagType.StartTag);
            sp=selectionManager.Validate(sp);
            SetSelection(new Selection(sp));
            UpdateCaretPosition(true);
            EnsureCaretVisible();
        }
        /// <summary>
        /// Attach an XmlDocument to this control.
        /// </summary>
        /// <param name="doc">The XmlDocument to attach.</param>
        /// <param name="valid">Indicates whether the document is valid according to its DTD.</param>
        /// <remarks>
        /// <para>This method detaches any existing XmlDocument and 
        /// attaches the new document. If the valid parameter is set to <b>false</b>,
        /// the document is validated according to the DTD, if present, so that any invalid
        /// nodes are highlighted. This can take a little time for very large documents, so
        /// if possible only valid documents should be attached. However, this feature allows
        /// the loading of well-formed but invalid documents into the control.</para>
        /// </remarks>
        public void Attach(XmlDocument doc, bool valid)
        {
            if ( !DoLicenseCheck(true) )
                return;

            Detach();

            if ( Handle.Equals(IntPtr.Zero) )
                return;

            if ( doc == null )
                return;

            nodocWnd.Visible=false;

            this.doc=doc;
            if ( doc.BaseURI.Length > 0 )
                docUri=new Uri(doc.BaseURI);

            try
            {
                GetStylesheetFromPi();
                FileReloadStylesheet();
                undoManager.Attach(doc);
                validationManager.Attach(doc, null);
                if ( !valid )
                    validationManager.ValidateAll();
            }
            catch ( Exception )
            {
                // clean up
                Detach();
                throw;
            }

            doc.NodeChanged+=new XmlNodeChangedEventHandler(NodeChanged);
            doc.NodeInserted+=new XmlNodeChangedEventHandler(NodeInserted);
            doc.NodeRemoved+=new XmlNodeChangedEventHandler(NodeRemoved);

            tooltip.Active=true;

            layoutEngine=new LayoutEngine(stylesheet);
            Reflow();

            if ( doc.DocumentElement != null )
            {
                SelectionPoint sel=new ElementSelectionPoint(doc.DocumentElement, TagType.StartTag);
                sel=selectionManager.NextSelectionPoint(sel);
                SetSelection(new Selection(sel));
            }
            UpdateCaretPosition();

            Invalidate(true);
        }
        private SelectionPoint GetLineSelectionPoint(int x, ref Rectangle rcCaret)
        {
            Point pt=caret.Location;
            pt.X=x;

            SelectionPoint sp=GetSelectionPoint(pt, ref rcCaret);

            if ( sp == null )
                sp=new ElementSelectionPoint(doc.DocumentElement, TagType.EndTag);

            return selectionManager.Validate(sp);
        }
Exemple #10
0
        /// <summary>
        /// Inserts an element.
        /// </summary>
        /// <param name="e">The XmlElement to insert.</param>
        /// <remarks>
        /// <para>If the current selection is a balanced range, the new element will wrap the
        /// content of the range. Otherwise the new element is inserted at the caret and the caret
        /// is positioned within the new element.</para>
        /// </remarks>
        public void Insert(XmlElement e)
        {
            CreateUndoPoint();

            Selection sel=currentSelection;
            if ( currentSelection.IsRange && currentSelection.IsBalanced )
            {
                sel=selectionManager.Wrap(currentSelection, e);
            }
            else
            {
                selectionManager.Insert(sel.Start, e);
                ElementSelectionPoint esp=new ElementSelectionPoint(e, TagType.EndTag);
                sel=new Selection(esp);
            }

            if ( e.ParentNode is XmlElement )
                // invalidate the parent node we've been inserted into
                Invalidate((XmlElement) e.ParentNode);
            else
                // this is document node so reflow all, primarily to
                // ensure caret is displayed correctly
                Reflow();

            SetSelection(sel);
            UpdateCaretPosition(true);
            EnsureCaretVisible();

            CreateUndoPoint();
        }