Пример #1
0
        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
        protected override bool UpdateLocation()
        {
            // TODO: L: there's some duplication here with ElementListPanelBase impl

            ValidationManager vm = editor.ValidationManager;

            if ((editor.Selection.IsEmpty || vm == null))
            {
                return(SetEmpty());
            }

            SelectionPoint sp = editor.Selection.Start;
            XmlNode        n;
            XmlElement     p = SelectionManager.GetInsertionContext(sp, out n);

            Console.WriteLine("Selection parent={0}, node={1}", p, n);

            if (parent == p)
            {
                // nothing changed (we don't care about the actual node)
                return(false);
            }

            node   = n;
            parent = p;

            return(true);
        }
Пример #3
0
        public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
        {
            startTag.GetCaretPosition(gr, x, y, sp, ref cpi);
            if (cpi.IsFinal)
            {
                return;
            }

            int pos = x + startTag.Width;

            foreach (TableCell cell in cells)
            {
                cell.GetCaretPosition(gr, pos, y, sp, ref cpi);
                if (cpi.IsFinal)
                {
                    return;
                }

                int cellWidth = ParentTable[cell.ElementNode].Column.Width;
                pos += cellWidth;
            }

            endTag.GetCaretPosition(gr, pos, y, sp, ref cpi);
            if (cpi.IsFinal)
            {
                return;
            }
        }
Пример #4
0
    public bool IsSameColor(SelectionPoint selectionPoint)
    {
        var tiles      = GetTiles();
        var otherTiles = selectionPoint.GetTiles();

        return(IsColorMatching() && selectionPoint.IsColorMatching() && tiles[0].tileColor == otherTiles[0].tileColor);
    }
 protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == "SetSelection")
     {
         pt = source.SetSelection;
     }
 }
        void Native_AfterTextChanged(object sender, global::Android.Text.AfterTextChangedEventArgs e)
        {
            if (pt != null && source.FormatCharacters != null)
            {
                var temp = pt;
                pt          = null;
                native.Text = temp.Text;
                if (temp.Start != -1)
                {
                    if (temp.End != -1)
                    {
                        native.SetSelection(temp.Start, temp.End);
                    }
                    else
                    {
                        if (temp.Start >= native.Text.Length)
                        {
                            temp.Start = native.Text.Length;
                        }
                        else
                        {
                            var before = source.BeforeChars;
                            if (before == "")
                            {
                                temp.Start = 1;
                            }
                            else
                            {
                                var text = native.Text;

                                for (int i = 0; i < text.Length; i++)
                                {
                                    string c = text[i].ToString();
                                    if (source.FormatCharacters.Where(ch => ch.ToString() == c.ToString()).Count() <= 0)
                                    {
                                        // no placeholder1
                                        if (before[0].ToString() == c)
                                        {
                                            before = before.Substring(1);
                                        }

                                        if (String.IsNullOrEmpty(before))
                                        {
                                            temp.Start = i + 1;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        native.SetSelection(temp.Start);
                    }
                }
                pt            = null;
                source.Locked = false;
            }
        }
Пример #7
0
 public void Select()
 {
     current    = this;
     isSelected = true;
     dotSpriteRenderer.enabled        = true;
     outlineSpriteRenderer.enabled    = true;
     dotGameObject.transform.position = position;
     FlipSprite();
 }
Пример #8
0
        public override Selection Perform(SelectionManager sm)
        {
            XmlElement e = XmlUtil.CreateElement(name, node.OwnerDocument);

            node.AppendChild(e);
            SelectionPoint sp = SelectionManager.CreateSelectionPoint(e, true);

            return(new Selection(sp));
        }
Пример #9
0
        public override Selection Perform(SelectionManager sm)
        {
            XmlElement e = XmlUtil.CreateElement(name, node.OwnerDocument);

            node.ParentNode.InsertBefore(e, node);
            SelectionPoint sp = SelectionManager.CreateSelectionPoint(e, true);

            return(new Selection(sp));
        }
Пример #10
0
 public SelectionPoint()
 {
     current               = this;
     grid                  = GameObject.Find("Grid").GetComponent <HexGrid>();
     dotGameObject         = GameObject.Find("SelectionPoint");
     dotSpriteRenderer     = dotGameObject.GetComponent <SpriteRenderer>();
     outlineGameobject     = dotGameObject.transform.GetChild(0).gameObject;
     outlineSpriteRenderer = outlineGameobject.GetComponent <SpriteRenderer>();
     spatialSearch.Add(this);
 }
Пример #11
0
        public override Selection Perform(SelectionManager sm)
        {
            SelectionPoint sp = SelectionManager.CreateSelectionPoint(node, true);

            sp = sm.NextSelectionPoint(sp);

            node.ParentNode.RemoveChild(node);

            return(new Selection(sp));
        }
Пример #12
0
 public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
 {
     if (ContainsSelectionPoint(sp))
     {
         cpi.UpdateLocation(x, y, Height, CaretSetting.Accurate);
     }
     else
     {
         cpi.UpdateLocation(x + Width, y, Height, CaretSetting.Fallback);
     }
 }
Пример #13
0
        private void UpdatSelectionPoint(SelectionPoint pt)
        {
            if (pt != null && this.Properties.FormatCharacters != null)
            {
                if (pt.Start != -1)
                {
                    if (pt.End != -1)
                    {
                        this.SetSelection(pt.Start, pt.End);
                    }
                    else
                    {
                        if (pt.Start >= this.Text.Length)
                        {
                            pt.Start = this.Text.Length;
                        }
                        else
                        {
                            var before = this.BeforeChars;
                            if (before == "")
                            {
                                pt.Start = 1;
                            }
                            else
                            {
                                var text = this.Text;

                                for (int i = 0; i < text.Length; i++)
                                {
                                    string c = text[i].ToString();
                                    if (this.Properties.FormatCharacters.Where(ch => ch.ToString() == c.ToString()).Count() <= 0)
                                    {
                                        // no placeholder1
                                        if (before[0].ToString() == c)
                                        {
                                            before = before.Substring(1);
                                        }

                                        if (String.IsNullOrEmpty(before))
                                        {
                                            pt.Start = i + 1;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        this.SetSelection(pt.Start);
                    }
                }
                pt = null;
            }
        }
Пример #14
0
 protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (e.PropertyName == "SetSelection")
     {
         pt = source.SetSelection;
     }
     else if (e.PropertyName == "FormatCharacters")
     {
         this.FormatCharacters = source.FormatCharacters.ToCharArray();
     }
 }
Пример #15
0
        public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
        {
            // TODO: M: this is very innefficient since it is called for all text nodes during search
            if (!ContainsSelectionPoint(sp))
            {
                cpi.UpdateLocation(x + Width, y, Height, CaretSetting.Fallback);
                return;
            }

            TextSelectionPoint tsp = (TextSelectionPoint)sp;

            CaretSetting mode = CaretSetting.Absolute;

            gr.PushFont(gr.GetFontHandle(style.FontDesc));
            try
            {
                int n = tsp.Index - start;
                if (n < 0)
                {
                    // position is not in visible part of the string, it's
                    // in whitespace that has been trimmed.
                    cpi.UseSecondary = true;
                    return;
                }
                else if (tsp.Index == 0)
                {
                    // caret can be put somewhere else if necessary
                    // TODO: L: this is a bit simplistic - will be wrong if text nodes are
                    //			split and first node ends with space and ends a line (!)
                    mode = CaretSetting.Accurate;
                }

                string text = Text;

                if (n > text.Length)
                {
                    // TODO: L: not sure exactly when this happens
                    n = text.Length;
                }

                text = ProcessText(text.Substring(0, n));

                int w = gr.MeasureText(text).Width;
                cpi.UpdateLocation(x + w, y, Height, mode);
            }
            finally
            {
                gr.PopFont();
            }
        }
Пример #16
0
        public override Selection Perform(SelectionManager sm)
        {
            SelectionPoint sp = SelectionManager.CreateSelectionPoint(node, false);

            sp = sm.NextSelectionPoint(sp);

            foreach (XmlNode n in node.ChildNodes)
            {
                node.ParentNode.InsertBefore(n, node);
            }

            node.ParentNode.RemoveChild(node);

            return(new Selection(sp));
        }
Пример #17
0
        public override bool ContainsSelectionPointInternal(SelectionPoint sp)
        {
            TextSelectionPoint tsp = sp as TextSelectionPoint;

            if (tsp == null)
            {
                return(false);
            }

            if (tsp.Node.NodeType == XmlNodeType.SignificantWhitespace)
            {
                return(true);
            }

            return(tsp.Index >= start - ignoreStart && tsp.Index < start + len + ignoreEnd);
        }
Пример #18
0
        public Rectangle GetCaretPosition(IGraphics gr, SelectionPoint sp, CaretDirection d)
        {
            if (rootBlock == null)
            {
                return(Rectangle.Empty);
            }

            CaretPositionInfo cpi = new CaretPositionInfo();

            rootBlock.GetCaretPosition(gr, 0, 0, sp, ref cpi);
            if (d == CaretDirection.LTR)
            {
                cpi.UseSecondary = true;
            }

            return(cpi.ToRectangle());
        }
Пример #19
0
    public bool IsAdjacent(SelectionPoint selectionPoint)
    {
        var            tiles      = GetTiles();
        var            otherTiles = selectionPoint.GetTiles();
        HashSet <Tile> totalTiles = new HashSet <Tile>();

        for (int i = 0; i < 3; i++)
        {
            totalTiles.Add(tiles[i]);
            totalTiles.Add(otherTiles[i]);
            if (totalTiles.Count != 2 * (i + 1))
            {
                return(true);
            }
        }

        return(false);
    }
Пример #20
0
        private void btnFind_Click(object sender, System.EventArgs e)
        {
            Selection sel = context.Selection;

            if (sel.IsEmpty)
            {
                return;
            }

            SelectionPoint sp = sel.Start;

            XmlNode n = sp.Node.SelectSingleNode(textXPath.Text);

            if (n != null)
            {
                sp = SelectionManager.CreateSelectionPoint(n, false);
                context.Selection = new Selection(sp);
            }
        }
Пример #21
0
        public override ILineItem FindSelectionPoint(SelectionPoint sp)
        {
            if (startTag.ContainsSelectionPoint(sp))
            {
                return(startTag);
            }
            else if (endTag.ContainsSelectionPoint(sp))
            {
                return(endTag);
            }

            foreach (TableCell c in cells)
            {
                ILineItem ret = c.FindSelectionPoint(sp);
                if (ret != null)
                {
                    return(ret);
                }
            }
            return(null);
        }
Пример #22
0
    private void CreateSelectionPoints()
    {
        List <Vector2Int> lowerNeighbourVertices = new List <Vector2Int>();

        lowerNeighbourVertices.Add(Vector2Int.left + Vector2Int.up);
        lowerNeighbourVertices.Add(Vector2Int.left);
        lowerNeighbourVertices.Add(Vector2Int.down);
        lowerNeighbourVertices.Add(Vector2Int.right);
        lowerNeighbourVertices.Add(Vector2Int.up + Vector2Int.right);

        for (int row = 1; row < gridSettings.horizontalCount; row += 2)
        {
            for (int col = 0; col < gridSettings.verticalCount; col++)
            {
                for (int i = 0; i < lowerNeighbourVertices.Count - 1; i++)
                {
                    var indexBase = new Vector2Int(row, col);
                    var index1    = indexBase + lowerNeighbourVertices[i];
                    var index2    = indexBase + lowerNeighbourVertices[i + 1];
                    try
                    {
                        var c1             = tiles[row, col].GetComponent <Tile>().GetCentoid();
                        var c2             = tiles[index1.x, index1.y].GetComponent <Tile>().GetCentoid();
                        var c3             = tiles[index2.x, index2.y].GetComponent <Tile>().GetCentoid();
                        var t              = (c1 + c2 + c3) / 3.0f;
                        var selectionPoint = new SelectionPoint();
                        selectionPoint.SetPosition(t);
                        selectionPoint.tileIndices[0] = indexBase;
                        selectionPoint.tileIndices[1] = index1;
                        selectionPoint.tileIndices[2] = index2;
                        selectionPoints.Add(selectionPoint);
                    }
                    catch (Exception e) { continue; }
                }
            }
        }
    }
Пример #23
0
        protected override bool UpdateLocation()
        {
            ValidationManager vm = editor.ValidationManager;

            Selection sel = editor.Selection;

            if ((sel.IsEmpty || vm == null))
            {
                return(SetEmpty());
            }

            XmlNode    n;
            XmlElement p;

            if (sel.IsSingleNode)
            {
                p = null;
                n = sel.Start.Node;
            }
            else
            {
                SelectionPoint sp = sel.Start;
                p = SelectionManager.GetInsertionContext(sp, out n);
            }

            if (node == n && parent == p)
            {
                // nothing changed
                return(false);
            }

            node   = n;
            parent = p;

            return(true);
        }
Пример #24
0
        protected override bool UpdateLocation()
        {
            ValidationManager vm = editor.ValidationManager;

            if ((editor.Selection.IsEmpty || vm == null))
            {
                return(SetEmpty());
            }

            SelectionPoint sp = editor.Selection.Start;
            XmlNode        n;
            XmlElement     p = SelectionManager.GetInsertionContext(sp, out n);

            if (node == n && parent == p)
            {
                // nothing changed
                return(false);
            }

            node   = n;
            parent = p;

            return(true);
        }
Пример #25
0
        private void StartSelection(SelectionPoint sp)
        {
            CreateUndoPoint();

            Selection sel=new Selection(selectionManager.Validate(sp), null);
            SetSelection(sel);
            UpdateCaretPosition(true);
            EnsureCaretVisible();
        }
Пример #26
0
        //protected void EditingDidBegin(object sender, EventArgs e)
        //{
        //		var x=0;
        //}


        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            //if (source.Delete && isSecond==false ){
            //	pt = source.SetSelection;
            //	isSecond=true;
            //	lastPos = pt.Start;
            //}
            var view = (MyEntry)Element;
            var PN   = e.PropertyName;

            if (PN == "SetSelection")
            {
                pt = source.SetSelection;
                if (pt != null && FormatCharacters != null)
                {
                    if (pt.Start != -1)
                    {
                        if (pt.End != -1)
                        {
                            var positionToSet = native.GetPosition(native.BeginningOfDocument, pt.Start);
                            native.SelectedTextRange = native.GetTextRange(positionToSet, positionToSet);
                            //native.SetSelection (pt.Start, pt.End);
                        }
                        else
                        {
                            if (pt.Start >= native.Text.Length)
                            {
                                pt.Start = native.Text.Length;
                            }
                            else
                            {
                                var before = source.BeforeChars;
                                if (before == "")
                                {
                                    pt.Start = 1;
                                }
                                else
                                {
                                    var text = native.Text;

                                    for (int i = 0; i < text.Length; i++)
                                    {
                                        string c = text[i].ToString();
                                        if (FormatCharacters.Where(ch => ch.ToString() == c.ToString()).Count() <= 0)
                                        {
                                            // no placeholder1
                                            //if (before [0].ToString () == c) {
                                            //	before = before.Substring (1);
                                            //}

                                            //if (String.IsNullOrEmpty (before)) {
                                            //	pt.Start = i + 1;
                                            //	break;
                                            //}
                                        }
                                    }
                                }
                            }
                            //var getPos =native.GetOffsetFromPosition(native.BeginningOfDocument,native.SelectedTextRange.Start);
                            //var positionToSet = native.GetPosition (native.BeginningOfDocument, getPos);
                            if (source.Locked && source.Delete)
                            {
                                if (source.SelectionStart - 1 < native.Text.Length)
                                {
                                    lastPos    = source.SelectionStart;
                                    ifIsInside = true;
                                }
                            }
                            else if (source.Locked && !source.Delete)
                            {
                                if (source.SelectionStart < native.Text.Length - 1)
                                {
                                    ifIsInside = true;
                                }
                                else
                                {
                                    ifIsInside = false;
                                }
                            }
                            else
                            {
                            }
                            //native.SetSelection(pt.Start);
                        }
                    }
                    pt = null;
                    //source.Delete = false;
                    source.Locked = false;
                }
            }
            else if (e.PropertyName == "FormatCharacters")
            {
                this.FormatCharacters = source.FormatCharacters.ToCharArray();
            }
            else if (e.PropertyName == "Text")
            {
                pt = source.SetSelection;
                if (source.Delete)
                {
                    //if (isSecond) {
                    if (ifIsInside)
                    {
                        //if (lastPos < source.SelectionStart) {
                        var positionToSet = native.GetPosition(native.BeginningOfDocument, source.SelectionStart - 1);
                        native.SelectedTextRange = native.GetTextRange(positionToSet, positionToSet);
                        //}
                        //isSecond = false;
                    }
                }
                else
                {
                    if (ifIsInside)
                    {
                        var positionToSet = native.GetPosition(native.BeginningOfDocument, source.SelectionStart + 1);
                        native.SelectedTextRange = native.GetTextRange(positionToSet, positionToSet);
                    }
                }
            }
            else if (e.PropertyName == MyEntry.FontProperty.PropertyName)
            {
                SetFont(view);
            }
            else if (e.PropertyName == MyEntry.XAlignProperty.PropertyName)
            {
                SetTextAlignment(view);
            }
            else if (e.PropertyName == MyEntry.HasBorderProperty.PropertyName)
            {
                SetBorder(view);
            }
            else if (e.PropertyName == MyEntry.PlaceholderTextColorProperty.PropertyName)
            {
                SetPlaceholderTextColor(view);
            }

            ResizeHeight();
        }
Пример #27
0
        public void ApplyTextChangeMask(string oldText, string newText)
        {
            if (this.Mask != null)
            {
                if (this.Locked == false && (this.LastText != this.Text) && String.IsNullOrEmpty(this.Text) == false)
                {
                    this.Locked = true;

                    oldText = oldText ?? "";

                    if (this.FormatCharacters == null)
                    {
                        this.Locked = false;
                        return;
                    }

                    var   chars         = this.FormatCharacters.ToCharArray();
                    Int32 adjustedStart = 0;
                    this.Locked = true;
                    var start  = this.SelectionStart;
                    var text   = this.Text.Replace(this.FormatCharacters.ToCharArray(), "");
                    var len    = text.Length;
                    var middle = false;
                    if (Delete && start > 0)
                    {
                        adjustedStart = adjustedStart - 1;
                        BeforeChars   = this.Text.Substring(0, start - 1).Replace(chars, "");
                    }
                    else
                    {
                        if (start != this.Text.Length - 1)
                        {
                            middle = true;
                            if (start > this.Text.Length - 1)
                            {
                                start       = this.Text.Length;
                                BeforeChars = this.Text;
                            }
                            else
                            {
                                BeforeChars = this.Text.Substring(0, start + 1).Replace(chars, "");
                            }
                        }
                    }

                    // check MaxLength for Mask
                    if (this.MaxLengthFromMask <= 0)
                    {
                        // check length of last Mask and set MaxLength of not set already
                        // this will set a MaxLength value to stop the mask
                        this.MaxLengthFromMask = this.Mask.Last().End;
                    }

                    var finalText = "";
                    var rule      = this.Mask.FirstOrDefault(r => r.End >= len);
                    if (rule == null)
                    {
                        // no rules found. get last rule
                        rule = this.Mask.Last();
                    }


                    if (rule.Mask != "")
                    {
                        var temp = ApplyMask(text, rule);
                        if (!Delete)
                        {
                            if (middle)
                            {
                                adjustedStart = 1;
                            }
                            else
                            {
                                if (temp.Length > oldText.Length)
                                {
                                    adjustedStart = temp.Length - oldText.Length;
                                }
                                else
                                {
                                    adjustedStart = 0;
                                    start         = temp.Length;
                                }
                            }
                        }
                        finalText = temp;
                        //var next = temp[start + adjustedStart-1];
                        this.LastText = temp;
                    }
                    else if (rule.Mask == "" && this.Delete)
                    {
                        finalText     = text;
                        this.LastText = text;
                    }
                    else
                    {
                        var oldLen = String.IsNullOrEmpty(oldText) ? 0 : oldText.Length;
                        if (newText.Length > oldLen)
                        {
                            adjustedStart++;
                        }
                        else
                        {
                            adjustedStart--;
                        }
                        finalText = this.Text.Replace(chars, "");
                    }

                    this.RawText = this.Text.Replace(chars, "");
                    var pt = new SelectionPoint(start + adjustedStart);
                    pt.Text      = finalText;
                    SetSelection = pt;
                }
            }
        }
        private void TabChanged(object sender, System.EventArgs e)
        {
            int tab = tabControl.SelectedIndex;

            if (tab == 0)
            {
                return;
            }

            XmlDocument doc = editor.Document;

            XmlProcessingInstruction stylePi = doc.SelectSingleNode(
                "processing-instruction('xeditnet-xsl')") as XmlProcessingInstruction;

            if (stylePi == null)
            {
                MessageBox.Show(this, "No xeditnet-xsl processing instruction found");
                return;
            }

            Uri baseUri = new Uri(doc.BaseURI);

            try
            {
                Uri uri = new Uri(baseUri, stylePi.Value);

                FileInfo fi        = new FileInfo(baseUri.LocalPath);
                string   outputDir = fi.DirectoryName;

                XslTransform xsl = new XslTransform();
                xsl.Load(uri.AbsolutePath);
                MultiXmlTextWriter mxtw = new MultiXmlTextWriter(outputDir + "/_default.html", null);
                try
                {
                    xsl.Transform(doc, null, mxtw, null);
                }
                finally
                {
                    mxtw.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
                return;
            }

            Selection sel = editor.Selection;

            if (sel.IsEmpty)
            {
                return;
            }

            string file = "_default.html";

            // TODO: M: deal better with entity ref at caret
            if (!sel.IsEmpty && sel.Start.Node.NodeType != XmlNodeType.EntityReference)
            {
                SelectionPoint sp = sel.Start;
                XmlElement     n  = sp.Node.SelectSingleNode("ancestor::*[@id != '']") as XmlElement;
                if (n != null)
                {
                    file = n.GetAttribute("id") + ".html";
                }
            }

            Uri currentPage = new Uri(baseUri, file);

            webBrowser.Navigate(currentPage.LocalPath);
        }
Пример #29
0
 private void UpdateCaretPosition(SelectionPoint sp, bool resetX)
 {
     UpdateCaretPosition(sp, resetX, CaretDirection.None);
 }
Пример #30
0
        public Rectangle GetCaretPosition(IGraphics gr, SelectionPoint sp, CaretDirection d)
        {
            if ( rootBlock == null )
                return Rectangle.Empty;

            CaretPositionInfo cpi=new CaretPositionInfo();
            rootBlock.GetCaretPosition(gr, 0, 0, sp, ref cpi);
            if ( d == CaretDirection.LTR )
                cpi.UseSecondary=true;

            return cpi.ToRectangle();
        }
Пример #31
0
        private void UpdateCaretPosition(SelectionPoint sp, bool resetX, CaretDirection d)
        {
            Rectangle rc=Rectangle.Empty;
            if ( layoutEngine != null )
            {
                using ( IGraphics gr=grFactory.CreateGraphics(this) )
                    rc=layoutEngine.GetCaretPosition(gr, sp, d);
            }
            if ( !rc.IsEmpty )
            {
                SetCaretPosition(rc.Location, rc.Height);

                if ( resetX )
                    linePosition=rc.Left;

                caret.Visible=!currentSelection.IsRange;
                return;
            }

            // TODO: M: not sure why caret does not update when window resizing
            caret.Visible=false;
            Logger.Log("WARN: failed to get caret position");
        }
Пример #32
0
		private void UpdatSelectionPoint(SelectionPoint pt)
		{
			if (pt != null && this.Properties.FormatCharacters != null)
			{
				if (pt.Start != -1) {
					if (pt.End != -1) {
						this.SetSelection (pt.Start, pt.End);
					} 
					else {
						if (pt.Start >= this.Text.Length) {
							pt.Start = this.Text.Length;
						}
						else
						{
							var before = this.BeforeChars;
							if (before == "")
							{
								pt.Start = 1;
							}
							else
							{
								var text = this.Text;

								for (int i = 0; i < text.Length; i++)
								{
									string c = text[i].ToString();
									if (this.Properties.FormatCharacters.Where(ch => ch.ToString() == c.ToString()).Count() <= 0)
									{
										// no placeholder1
										if (before[0].ToString() == c)
										{
											before = before.Substring(1);												
										}

										if (String.IsNullOrEmpty(before))
										{
											pt.Start = i+1;
											break;
										}
									}
								}
							}	
						}
						this.SetSelection(pt.Start);
					}
				}
				pt = null;
			}
		}
Пример #33
0
 public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
 {
     if ( ContainsSelectionPoint(sp) )
         cpi.UpdateLocation(x, y, Height, CaretSetting.Accurate);
     else
         cpi.UpdateLocation(x+Width, y, Height, CaretSetting.Fallback);
 }
Пример #34
0
 public override bool ContainsSelectionPointInternal(SelectionPoint sp)
 {
     return true;
 }
Пример #35
0
 public override bool ContainsSelectionPointInternal(SelectionPoint sp)
 {
     return(true);
 }
Пример #36
0
        public override void Draw(DrawContext dc, int x, int y, int baseline, int height, Style c)
        {
            Debug.Assert(Height >= 0, "TextFragment is not composed!");

            Rectangle rc = GetBoundingRect(x, y);

            rc.Height += height - Height;
            if (!dc.ClippingRectangle.IntersectsWith(rc))
            {
                return;
            }

            string text       = ProcessText(Text);     // .Replace('\r', ' ').Replace('\t', ' ').Replace('\n', ' ');
            int    startIndex = 0;
            int    endIndex   = 0;

            Color bkCol = c.Stylesheet.HighlightColor;

            bool inError = dc.InvalidInfo.Contains(Node);

            dc.Graphics.PushFont(dc.Graphics.GetFontHandle(style.FontDesc));
//			dc.Graphics.PushFont(style.FontHandle);
            try
            {
                if (selection != null)
                {
                    SelectionPoint startSel = selection.Start;
                    SelectionPoint endSel   = selection.End;

                    // by default everything selected
                    endIndex = text.Length;

                    if (ContainsSelectionPoint(startSel))
                    {
                        TextSelectionPoint sel = (TextSelectionPoint)startSel;
                        startIndex = sel.Index - start;
                        if (startIndex < 0)
                        {
                            startIndex = 0;
                        }
                    }
                    if (ContainsSelectionPoint(endSel))
                    {
                        TextSelectionPoint sel = (TextSelectionPoint)endSel;
                        endIndex = sel.Index - start;
                        if (endIndex < 0)
                        {
                            endIndex = text.Length;
                        }
                    }
                }

                int       dx     = dc.Graphics.MeasureText(text).Width;
                Rectangle rcText = new Rectangle(x, y, dx, height);
                DrawText(dc, rcText, baseline, text, bkCol, Color.White, startIndex, endIndex);

                if (inError)
                {
                    DrawErrorIndicator(dc, x, x, dx, y + baseline, false);
                }
            }
            finally
            {
                dc.Graphics.PopFont();
            }
        }
        protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (e.PropertyName == "SetSelection")
            {
                pt = source.SetSelection;
                if (pt != null && source.FormatCharacters != null)
                {
                    var temp = pt;
                    pt          = null;
                    native.Text = temp.Text;
                    if (temp.Start != -1)
                    {
                        if (temp.End != -1)
                        {
                            var positionToSet = native.GetPosition(native.BeginningOfDocument, temp.Start);
                            native.SelectedTextRange = native.GetTextRange(positionToSet, positionToSet);
                        }
                        else
                        {
                            if (temp.Start >= native.Text.Length)
                            {
                                temp.Start = native.Text.Length;
                            }
                            else
                            {
                                var before = source.BeforeChars;
                                if (before == "")
                                {
                                    temp.Start = 1;
                                }
                                else
                                {
                                    var text = native.Text;

                                    for (int i = 0; i < text.Length; i++)
                                    {
                                        string c = text[i].ToString();
                                        if (source.FormatCharacters.Where(ch => ch.ToString() == c.ToString()).Count() <= 0)
                                        {
                                            // no placeholder1
                                            if (before[0].ToString() == c)
                                            {
                                                before = before.Substring(1);
                                            }

                                            if (String.IsNullOrEmpty(before))
                                            {
                                                temp.Start = i + 1;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            var positionToSet = native.GetPosition(native.BeginningOfDocument, temp.Start);
                            native.SelectedTextRange = native.GetTextRange(positionToSet, positionToSet);
                        }
                    }
                }
                source.Locked = false;
            }
        }
Пример #38
0
        public override bool ContainsSelectionPointInternal(SelectionPoint sp)
        {
            TextSelectionPoint tsp=sp as TextSelectionPoint;
            if ( tsp == null )
                return false;

            if ( tsp.Node.NodeType == XmlNodeType.SignificantWhitespace )
            {
                return true;
            }

            return (tsp.Index >= start && tsp.Index < start+len);
        }
Пример #39
0
        public override void GetCaretPosition(IGraphics gr, int x, int y, SelectionPoint sp, ref CaretPositionInfo cpi)
        {
            // TODO: M: this is very innefficient since it is called for all text nodes during search
            if ( !ContainsSelectionPoint(sp) )
            {
                cpi.UpdateLocation(x+Width, y, Height, CaretSetting.Fallback);
                return;
            }

            TextSelectionPoint tsp=(TextSelectionPoint) sp;

            CaretSetting mode=CaretSetting.Absolute;

            gr.PushFont(gr.GetFontHandle(style.FontDesc));
            try
            {
                int n=tsp.Index-start;
                if ( n < 0 )
                {
                    // position is not in visible part of the string, it's
                    // in whitespace that has been trimmed.
                    cpi.UseSecondary=true;
                    return;
                } else if ( tsp.Index == 0 )
                {
                    // caret can be put somewhere else if necessary
                    // TODO: L: this is a bit simplistic - will be wrong if text nodes are
                    //			split and first node ends with space and ends a line (!)
                    mode=CaretSetting.Accurate;
                }

                string text=Text;

                if ( n > text.Length )
                    // TODO: L: not sure exactly when this happens
                    n=text.Length;

                text=ProcessText(text.Substring(0, n));

                int w=gr.MeasureText(text).Width;
                cpi.UpdateLocation(x+w, y, Height, mode);
            }
            finally
            {
                gr.PopFont();
            }
        }