Class representing a point in a text. where x is the column and y is the row.
Example #1
0
        /// <summary>
        /// Converts a Column/Row index position into a char index
        /// </summary>
        /// <param name="pos">TextPoint where x is column and y is row index</param>
        /// <returns>Char index in the document text</returns>
        public int PointToIntPos(TextPoint pos)
        {
            int y = 0;
            int p = 0;
            foreach (Row r in this)
            {
                if (y == pos.Y)
                    break;
                p += r.Text.Length + Environment.NewLine.Length;
                y++;
            }

            return p + Math.Min(pos.X, this[pos.Y].Text.Length);
        }
Example #2
0
        //Returns the span object at the given position
        /// <summary>
        /// Gets a span object form a given column , Row index
        /// (This only applies if the row is fully parsed)
        /// </summary>
        /// <param name="p">Column and Rowindex</param>
        /// <returns>span object at the given position</returns>
        public Span GetSegmentFromPos(TextPoint p)
        {
            Row xtr = this[p.Y];
            int CharNo = 0;

            if (xtr.Count == 0)
                return xtr.startSpan;

            Span prev = xtr.startSpan;
            foreach (Word w in xtr)
            {
                if (w.Text.Length + CharNo > p.X)
                {
                    if (CharNo == p.X)
                        return prev;
                    return w.Span;
                }
                CharNo += w.Text.Length;
                prev = w.Span;
            }

            return xtr.endSpan;
        }
Example #3
0
        //the specific word that contains the char in point p
        /// <summary>
        /// Gets a Word object form a given column , Row index
        /// (this only applies if the row is fully parsed)
        /// </summary>
        /// <param name="p">Column and Rowindex</param>
        /// <returns>Word object at the given position</returns>
        public Word GetFormatWordFromPos(TextPoint p)
        {
            Row xtr = this[p.Y];
            int CharNo = 0;
            Word CorrectWord = null;
            foreach (Word w in xtr.FormattedWords)
            {
                if (CorrectWord != null)
                {
                    if (w.Text == "")
                        return w;
                    return CorrectWord;
                }

                if (w.Text.Length + CharNo > p.X || w == xtr[xtr.Count - 1])
                {
                    //return w;
                    CorrectWord = w;
                }
                else
                {
                    CharNo += w.Text.Length;
                }
            }
            return CorrectWord;
        }
Example #4
0
 /// <summary>
 /// Scrolls the active view to a specific position.
 /// </summary>
 /// <param name="Pos"></param>
 public void ScrollIntoView(TextPoint Pos)
 {
     ((EditViewControl) _ActiveView).ScrollIntoView(Pos);
 }
Example #5
0
        /// <summary>
        /// Perform an undo action
        /// </summary>
        /// <returns>The position where the caret should be placed</returns>
        public TextPoint Undo()
        {
            if (UndoStep == 0)
                return new TextPoint(-1, -1);


            UndoBlockCollection ActionGroup = UndoBuffer[UndoStep - 1];
            UndoBlock undo = ActionGroup[0];

            for (int i = ActionGroup.Count - 1; i >= 0; i--)
            {
                undo = ActionGroup[i];
                //TextPoint tp=new TextPoint (undo.Position.X,undo.Position.Y);
                switch (undo.Action)
                {
                    case UndoAction.DeleteRange:
                        InsertText(undo.Text, undo.Position.X, undo.Position.Y, false);
                        break;
                    case UndoAction.InsertRange:
                        {
                            TextRange r = GetRangeFromText(undo.Text, undo.Position.X, undo.Position.Y);
                            DeleteRange(r, false);
                        }
                        break;
                    default:
                        break;
                }
            }

            UndoStep--;
            ResetVisibleRows();

            //no undo steps left , the document is not dirty
            if (UndoStep == 0)
                Modified = false;

            var tp = new TextPoint(undo.Position.X, undo.Position.Y);
            OnUndoBufferChanged();
            return tp;
        }
Example #6
0
 /// <summary>
 /// Sets the position of the caret
 /// </summary>
 /// <param name="pos">Point containing the new x and y positions</param>
 public void SetPos(TextPoint pos)
 {
     Position = pos;
     RememberXPos();
 }
Example #7
0
        // to what control does the caret belong??

        #endregion

        #region Constructor(s)

        /// <summary>
        /// Caret constructor
        /// </summary>
        /// <param name="control">The control that will use the caret</param>
        public Caret(EditViewControl control)
        {
            Position = new TextPoint(0, 0);
            Control = control;
        }
Example #8
0
        /// <summary>
        /// Moves the caret down x rows.
        /// </summary>
        /// <param name="rows">The number of rows the caret should be moved down</param>
        /// <param name="Select">True if a selection should be created from the current caret pos to the new pos</param>
        public void MoveDown(int rows, bool Select)
        {
            int x = OldLogicalXPos;
            CropPosition();
            //this.Position.Y +=rows;
            try
            {
                int pos = CurrentRow.VisibleIndex;
                pos += rows;
                if (pos > Control.Document.VisibleRows.Count - 1)
                    pos = Control.Document.VisibleRows.Count - 1;

                Row r = Control.Document.VisibleRows[pos];
                pos = r.Index;
                Position.Y = pos;

                //				for (int i=0;i<rows;i++)
                //				{
                //					this.Position.Y =  this.CurrentRow.NextVisibleRow.Index;
                //					
                //				}
                if (CurrentRow.IsCollapsed)
                {
                    x = 0;
                }
            }
            catch {}
            finally
            {
                CropPosition();
                LogicalPosition = new TextPoint(x, Position.Y);
                CropPosition();
                CaretMoved(Select);
            }
        }
Example #9
0
        /// <summary>
        /// Moves the caret down one row.
        /// </summary>
        /// <param name="Select">True if a selection should be created from the current caret pos to the new pos</param>
        public void MoveDown(bool Select)
        {
            CropPosition();
            int x = OldLogicalXPos;
            //error here
            try
            {
                Row r = CurrentRow;
                Row r2 = r.NextVisibleRow;
                if (r2 == null)
                    return;

                Position.Y = r2.Index;
                if (CurrentRow.IsCollapsed)
                {
                    x = 0;
                }
            }
            catch {}
            finally
            {
                CropPosition();
                LogicalPosition = new TextPoint(x, Position.Y);
                CropPosition();
                CaretMoved(Select);
            }
        }
Example #10
0
 /// <summary>
 /// Moves the caret up one row.
 /// </summary>
 /// <param name="Select">True if a selection should be created from the current caret pos to the new pos</param>
 public void MoveUp(bool Select)
 {
     CropPosition();
     int x = OldLogicalXPos;
     //error here
     try
     {
         if (CurrentRow != null && CurrentRow.PrevVisibleRow != null)
         {
             Position.Y = CurrentRow.PrevVisibleRow.Index;
             if (CurrentRow.IsCollapsed)
             {
                 x = 0;
             }
         }
     }
     catch {}
     finally
     {
         CropPosition();
         LogicalPosition = new TextPoint(x, Position.Y);
         CropPosition();
         CaretMoved(Select);
     }
 }
Example #11
0
        /// <summary>
        /// Moves the caret up x rows
        /// </summary>
        /// <param name="rows">Number of rows the caret should be moved up</param>
        /// <param name="Select">True if a selection should be created from the current caret pos to the new pos</param>
        public void MoveUp(int rows, bool Select)
        {
            CropPosition();
            int x = OldLogicalXPos;
            try
            {
                int pos = CurrentRow.VisibleIndex;
                pos -= rows;
                if (pos < 0)
                    pos = 0;
                Row r = Control.Document.VisibleRows[pos];
                pos = r.Index;


                Position.Y = pos;

                //				for (int i=0;i<rows;i++)
                //				{
                //					this.Position.Y =  this.CurrentRow.PrevVisibleRow.Index;
                //				}
                if (CurrentRow.IsCollapsed)
                {
                    x = 0;
                }
            }
            catch {}
            CropPosition();
            LogicalPosition = new TextPoint(x, Position.Y);
            CropPosition();
            CaretMoved(Select);
        }
Example #12
0
        /// <summary>
        /// Converts a Column/Row index position into a char index
        /// </summary>
        /// <param name="pos">TextPoint where x is column and y is row index</param>
        /// <returns>Char index in the document text</returns>
        public int PointToIntPos(TextPoint pos)
        {
            int y = 0;
            int p = 0;
            foreach (Row r in this)
            {
                if (y == pos.Y)
                    break;
                p += r.Text.Length + Environment.NewLine.Length;
                y++;
            }

            // Not sure why but if I paste multiple lines
            // then this causes a crash because pos.Y is greater
            // than the number of elements available through the []
            // operator.
            int yToUse = Math.Min(this.Count-1, pos.Y);

            return p + Math.Min(pos.X, this[yToUse].Text.Length);
        }
Example #13
0
        private Point GetTextPointPixelPos(TextPoint tp)
        {
            Row xtr = Control.Document[tp.Y];
            if (xtr.RowState == RowState.SpanParsed)
                Control.Document.Parser.ParseRow(xtr.Index, true);

            Row r = xtr.IsCollapsedEndPart ? xtr.Expansion_StartRow : xtr;

            int index = r.VisibleIndex;
            int yPos = (index - Control.View.FirstVisibleRow);
            if (yPos < 0 || yPos > Control.View.VisibleRowCount)
                return new Point(-1, -1);

            yPos *= Control.View.RowHeight;

            bool Collapsed = (xtr.IsCollapsedEndPart);
            int pos = MeasureRow(xtr, tp.X).Width + 1;


            if (Collapsed)
            {
                pos += xtr.Expansion_PixelStart;
                pos -= MeasureRow(xtr, xtr.Expansion_StartChar).Width;
            }

            int xPos = pos + Control.View.TextMargin - Control.View.ClientAreaStart;

            if (xPos < Control.View.TextMargin || xPos > Control.View.ClientAreaWidth + Control.View.TextMargin)
                return new Point(-1, -1);


            return new Point(xPos, yPos);
        }
Example #14
0
 /// <summary>
 /// Scrolls a given position in the text into view.
 /// </summary>
 /// <param name="Pos">Position in text</param>
 public void ScrollIntoView(TextPoint Pos)
 {
     TextPoint tmp = Caret.Position;
     Caret.Position = Pos;
     Caret.CurrentRow.EnsureVisible();
     ScrollIntoView();
     Caret.Position = tmp;
     Invalidate();
 }
Example #15
0
        /// <summary>
        /// Assigns a new text to the row.
        /// </summary>
        /// <param name="text"></param>
        public void SetText(string text)
        {
            Document.StartUndoCapture();
            var tp = new TextPoint(0, Index);
            var tr = new TextRange {FirstColumn = 0, FirstRow = tp.Y, LastColumn = Text.Length, LastRow = tp.Y};

            Document.StartUndoCapture();
            //delete the current line
            Document.PushUndoBlock(UndoAction.DeleteRange, Document.GetRange(tr), tr.FirstColumn, tr.FirstRow);
            //alter the text
            Document.PushUndoBlock(UndoAction.InsertRange, text, tp.X, tp.Y);
            Text = text;
            Document.EndUndoCapture();
            Document.InvokeChange();
        }
Example #16
0
        /// <summary>
        /// Assigns a new text to the row.
        /// </summary>
        /// <param name="text"></param>
        public void SetText(string Text)
        {
            this.Document.StartUndoCapture();
            TextPoint tp = new TextPoint(0, this.Index);
            TextRange tr = new TextRange();
            tr.FirstColumn = 0;
            tr.FirstRow = tp.Y;
            tr.LastColumn = this.Text.Length;
            tr.LastRow = tp.Y;

            this.Document.StartUndoCapture();
            //delete the current line
            this.Document.PushUndoBlock(UndoAction.DeleteRange, this.Document.GetRange(tr), tr.FirstColumn, tr.FirstRow, this.RevisionMark);
            //alter the text
            this.Document.PushUndoBlock(UndoAction.InsertRange, Text, tp.X, tp.Y, this.RevisionMark);
            this.Text = Text;
            this.Document.EndUndoCapture();
            this.Document.InvokeChange();
        }