コード例 #1
0
ファイル: LayoutTests.cs プロジェクト: jugglingcats/XEditNet
        public void CommentHitTestError()
        {
            string test="<p><!--OddPage--></p>";
            XmlDocument doc=new XmlDocument();
            doc.LoadXml(test);

            Stylesheet s=new Stylesheet();
            s.BindStyles(doc.NameTable);

            Rectangle rc=new Rectangle(0, 0, 500, int.MaxValue);

            using ( IGraphics gr=new DummyGraphics() )
            {
                DrawContext ctx=new DrawContext(gr, Point.Empty, rc, rc, null, new DocumentType(), null);
                LayoutEngine layoutEngine=new LayoutEngine(s);

                layoutEngine.Reflow(ctx, doc.DocumentElement);

                Console.WriteLine("Bounds {0}", layoutEngine.BoundingRect);
                for (int x=0; x< layoutEngine.BoundingRect.Width; x+=10)
                {
                    HitTestInfo hti=layoutEngine.GetHitTestInfo(gr, new Point(x,8));
                    SelectionPoint sp=hti.SelectionPoint;
                    Console.WriteLine("Hit test at {0} = {1}", x, sp);
                }
            }
        }
コード例 #2
0
ファイル: LayoutTests.cs プロジェクト: jugglingcats/XEditNet
        public void HitTestHandling()
        {
            string test="<p><b>xxxxxxxxxxxxx</b></p>";
            XmlDocument doc=new XmlDocument();
            doc.LoadXml(test);

            Stylesheet s=//Stylesheet.Load("c:/tmp/website/site.style", doc.NameTable);
            new Stylesheet();
            s.BindStyles(doc.NameTable);

            Rectangle rc=new Rectangle(0, 0, 500, int.MaxValue);

            using ( IGraphics gr=new DummyGraphics() )
            {
                DrawContext ctx=new DrawContext(gr, Point.Empty, rc, rc, null, new DocumentType(), null);
                LayoutEngine layoutEngine=new LayoutEngine(s);

                layoutEngine.Reflow(ctx, doc.DocumentElement);

                layoutEngine.GetHitTestInfo(gr, new Point(141,16));
            }
        }
コード例 #3
0
ファイル: XEditNetCtrl.cs プロジェクト: jugglingcats/XEditNet
        /// <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);
        }
コード例 #4
0
ファイル: XEditNetCtrl.cs プロジェクト: jugglingcats/XEditNet
        private void Reflow()
        {
            //			Console.WriteLine("XEditNetCtrl: Reflow");

            if ( doc == null || doc.DocumentElement == null )
                return;

            LayoutEngine le=new LayoutEngine(stylesheet);

            Size sz=new Size();

            //			Console.WriteLine("Reflow: Create graphics from control");
            using ( IGraphics gr=grFactory.CreateGraphics(this) )
            {
                Rectangle rc=VisibleRectangle;
                rc.Height=0;

                DrawContext dc=new DrawContext(gr, new Point(-OffsetX, -OffsetY), rc, rc, validationManager.InvalidNodes, validationManager.DocumentType, currentSelection.Start);
                sz=le.Reflow(dc, doc.DocumentElement);
            }

            layoutEngine=le;

            if ( currentSelection.IsRange )
            {
                layoutEngine.Selection=currentSelection;
                Invalidate(true);
            }

            UpdateCaretPosition();
            ResetScrollbars(sz);
        }
コード例 #5
0
ファイル: XEditNetCtrl.cs プロジェクト: jugglingcats/XEditNet
        //        protected new void SetScrollState(int bit, bool value)
        //        {
        //            base.SetScrollState(bit, value);
        //            base.SetScrollState(4, true);
        //        }
        //        protected new bool VScroll
        //        {
        //            get { return true; }
        //            set { base.VScroll=true; }
        //        }
        /// <seebase/>
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            if ( Size.Width == 0 )
            {
                // minimise
                Console.WriteLine("Resize not actioned - width is 0");
                return;
            }

            if ( currentSize.Width != ClientRectangle.Width )
            {
                if ( caret != null )
                    caret.Visible=false;

            //				Logger.Log("Recreating layoutEngine");
                layoutEngine=new LayoutEngine(stylesheet);
                reflowTimer.Stop();
                reflowTimer.Start();
            }
            //			else if ( layoutEngine != null )
            //			{
            //				ResetScrollbars(layoutEngine.BoundingRect.Size);
            //			}

            currentSize=ClientRectangle.Size;
            if ( nodocWnd != null )
                nodocWnd.AutoSize();
        }
コード例 #6
0
ファイル: XEditNetCtrl.cs プロジェクト: jugglingcats/XEditNet
 public void ViewTagsOn()
 {
     stylesheet.TagMode=TagViewMode.Full;
     reflowTimer.Stop();
     layoutEngine=new LayoutEngine(stylesheet);
     reflowTimer.Start();
     Invalidate(true);
 }
コード例 #7
0
ファイル: XEditNetCtrl.cs プロジェクト: jugglingcats/XEditNet
        /// <summary>
        /// Detaches the current XmlDocument, if any, from the control.
        /// </summary>
        /// <remarks>
        /// Use this method to remove any association between the XmlDocument attached to the control
        /// and the control. All events handlers are detached and so on. You might use this method before
        /// making extensive changes to the XmlDocument due to the overhead of undo/redo support and
        /// other change tracking performed by XEditNet.
        /// </remarks>
        public void Detach()
        {
            if ( doc == null )
                return;

            // TODO: M: this isn't working - when undo over new doc element
            caret.Visible=false;

            doc.NodeChanged-=new XmlNodeChangedEventHandler(NodeChanged);
            doc.NodeInserted-=new XmlNodeChangedEventHandler(NodeInserted);
            doc.NodeRemoved-=new XmlNodeChangedEventHandler(NodeRemoved);
            undoManager.Detach();
            validationManager.Detach();

            SetSelection(Selection.Empty);

            doc=null;
            docUri=null;
            layoutEngine=null;
            tooltip.Active=false;
            Invalidate(true);

            nodocWnd.Visible=true;
            nodocWnd.ShowStartMessage=true;

            return;
        }
コード例 #8
0
ファイル: LayoutTests.cs プロジェクト: jugglingcats/XEditNet
        public void WhitespaceHandling1()
        {
            string test="aaaa bbbb  cccc";
            XmlDocument doc=new XmlDocument();
            doc.LoadXml("<doc>"+test+"</doc>");

            Stylesheet s=new Stylesheet();
            s.BindStyles(doc.NameTable);

            //			Rectangle rc=new Rectangle(0, 0, 480, int.MaxValue);
            Rectangle rc=new Rectangle(0, 0, 110, int.MaxValue);

            using ( IGraphics gr=new DummyGraphics() )
            {
                DrawContext ctx=new DrawContext(gr, Point.Empty, rc, rc, null, new DocumentType(), null);
                LayoutEngine layoutEngine=new LayoutEngine(s);
                layoutEngine.Reflow(ctx, doc.DocumentElement);

                SelectionPoint start=new TextSelectionPoint(doc.DocumentElement.FirstChild, 11);
                Console.WriteLine("Getting caret pos for {0}", start);
                Rectangle c=layoutEngine.GetCaretPosition(gr, start, CaretDirection.None);
                Console.WriteLine("Char {0} at {1}", start.ToString(), c);
            }
        }