GetLogicalPosition() public method

returns line/column for a visual point position
public GetLogicalPosition ( Point mousePosition ) : TextLocation
mousePosition Point
return TextLocation
Ejemplo n.º 1
0
        protected void RequestToolTip(Point mousePos)
        {
            if (toolTipRectangle.Contains(mousePos))
            {
                if (!toolTipActive)
                {
                    ResetMouseEventArgs();
                }
                return;
            }

            //Console.WriteLine("Request tooltip for " + mousePos);

            toolTipRectangle = new Rectangle(mousePos.X - 4, mousePos.Y - 4, 8, 8);

            TextLocation logicPos = textView.GetLogicalPosition(mousePos.X - textView.DrawingPosition.Left,
                                                                mousePos.Y - textView.DrawingPosition.Top);
            bool inDocument = textView.DrawingPosition.Contains(mousePos) &&
                              logicPos.Y >= 0 && logicPos.Y < Document.TotalNumberOfLines;
            ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(mousePos, logicPos, inDocument);

            OnToolTipRequest(args);
            if (args.ToolTipShown)
            {
                //Console.WriteLine("Set tooltip to " + args.toolTipText);
                toolTipActive = true;
                SetToolTip(args.toolTipText, inDocument ? logicPos.Y + 1 : -1);
            }
            else
            {
                CloseToolTip();
            }
        }
Ejemplo n.º 2
0
        protected void OnDragOver(object sender, DragEventArgs e)
        {
            if (!this.textArea.Focused)
            {
                this.textArea.Focus();
            }
            Point client = this.textArea.PointToClient(new Point(e.X, e.Y));

            if (!this.textArea.TextView.DrawingPosition.Contains(client.X, client.Y))
            {
                e.Effect = DragDropEffects.None;
                return;
            }
            TextView     textView        = this.textArea.TextView;
            int          x               = client.X - this.textArea.TextView.DrawingPosition.X;
            int          y               = client.Y;
            Rectangle    drawingPosition = this.textArea.TextView.DrawingPosition;
            TextLocation logicalPosition = textView.GetLogicalPosition(x, y - drawingPosition.Y);
            int          num             = Math.Min(this.textArea.Document.TotalNumberOfLines - 1, Math.Max(0, logicalPosition.Y));

            this.textArea.Caret.Position = new TextLocation(logicalPosition.X, num);
            this.textArea.SetDesiredColumn();
            if (!e.Data.GetDataPresent(typeof(string)) || this.textArea.IsReadOnly(this.textArea.Caret.Offset))
            {
                e.Effect = DragDropEffects.None;
                return;
            }
            e.Effect = TextAreaDragDropHandler.GetDragDropEffect(e);
        }
        private void ExtendSelectionToMouse()
        {
            Point        point           = this.textArea.mousepos;
            TextView     textView        = this.textArea.TextView;
            int          x               = point.X;
            Rectangle    drawingPosition = this.textArea.TextView.DrawingPosition;
            int          num             = Math.Max(0, x - drawingPosition.X);
            int          y               = point.Y;
            Rectangle    rectangle       = this.textArea.TextView.DrawingPosition;
            TextLocation logicalPosition = textView.GetLogicalPosition(num, y - rectangle.Y);
            int          y1              = logicalPosition.Y;

            logicalPosition = this.textArea.Caret.ValidatePosition(logicalPosition);
            TextLocation position = this.textArea.Caret.Position;

            if (position == logicalPosition && this.textArea.SelectionManager.selectFrom.@where != 1)
            {
                return;
            }
            if (this.textArea.SelectionManager.selectFrom.@where != 1)
            {
                this.textArea.Caret.Position = logicalPosition;
            }
            else if (logicalPosition.Y >= this.textArea.SelectionManager.SelectionStart.Y)
            {
                this.textArea.Caret.Position = this.textArea.SelectionManager.NextValidPosition(logicalPosition.Y);
            }
            else
            {
                this.textArea.Caret.Position = new TextLocation(0, logicalPosition.Y);
            }
            if (this.minSelection.IsEmpty || this.textArea.SelectionManager.SelectionCollection.Count <= 0 || this.textArea.SelectionManager.selectFrom.@where != 2)
            {
                this.textArea.SelectionManager.ExtendSelection(position, this.textArea.Caret.Position);
            }
            else
            {
                ISelection   item         = this.textArea.SelectionManager.SelectionCollection[0];
                TextLocation textLocation = (this.textArea.SelectionManager.GreaterEqPos(this.minSelection, this.maxSelection) ? this.maxSelection : this.minSelection);
                TextLocation position1    = (this.textArea.SelectionManager.GreaterEqPos(this.minSelection, this.maxSelection) ? this.minSelection : this.maxSelection);
                if (this.textArea.SelectionManager.GreaterEqPos(position1, logicalPosition) && this.textArea.SelectionManager.GreaterEqPos(logicalPosition, textLocation))
                {
                    this.textArea.SelectionManager.SetSelection(textLocation, position1);
                }
                else if (!this.textArea.SelectionManager.GreaterEqPos(position1, logicalPosition))
                {
                    int offset = this.textArea.Document.PositionToOffset(logicalPosition);
                    position1 = this.textArea.Document.OffsetToPosition(this.FindWordEnd(this.textArea.Document, offset));
                    this.textArea.SelectionManager.SetSelection(textLocation, position1);
                }
                else
                {
                    int offset1 = this.textArea.Document.PositionToOffset(logicalPosition);
                    textLocation = this.textArea.Document.OffsetToPosition(this.FindWordStart(this.textArea.Document, offset1));
                    this.textArea.SelectionManager.SetSelection(textLocation, position1);
                }
            }
            this.textArea.SetDesiredColumn();
        }
Ejemplo n.º 4
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (!_toolTipRectangle.Contains(e.Location))
            {
                _toolTipRectangle = Rectangle.Empty;

                if (_toolTipActive)
                {
                    RequestToolTip(e.Location);
                }
            }

            foreach (IMargin margin in _leftMargins)
            {
                if (margin.DrawingPosition.Contains(e.X, e.Y))
                {
                    Cursor = margin.Cursor;
                    margin.HandleMouseMove(new Point(e.X, e.Y), e.Button);

                    if (_lastMouseInMargin != margin)
                    {
                        if (_lastMouseInMargin != null)
                        {
                            _lastMouseInMargin.HandleMouseLeave(EventArgs.Empty);
                        }
                        _lastMouseInMargin = margin;
                    }
                    return;
                }
            }

            if (_lastMouseInMargin != null)
            {
                _lastMouseInMargin.HandleMouseLeave(EventArgs.Empty);
                _lastMouseInMargin = null;
            }

            if (TextView.DrawingPosition.Contains(e.X, e.Y))
            {
                TextLocation realmousepos = TextView.GetLogicalPosition(e.X - TextView.DrawingPosition.X, e.Y - TextView.DrawingPosition.Y);
                if (SelectionManager.IsSelected(Document.PositionToOffset(realmousepos)) && MouseButtons == MouseButtons.None)
                {
                    // mouse is hovering over a selection, so show default mouse
                    Cursor = Cursors.Default;
                }
                else
                {
                    // mouse is hovering over text area, not a selection, so show the textView cursor
                    Cursor = TextView.Cursor;
                }
                return;
            }

            Cursor = Cursors.Default;
        }
        private void TextAreaClick(object sender, EventArgs e)
        {
            Point point = this.textArea.mousepos;

            if (this.dodragdrop)
            {
                return;
            }
            if (this.clickedOnSelectedText && this.textArea.TextView.DrawingPosition.Contains(point.X, point.Y))
            {
                this.textArea.SelectionManager.ClearSelection();
                TextView     textView        = this.textArea.TextView;
                int          x               = point.X - this.textArea.TextView.DrawingPosition.X;
                int          y               = point.Y;
                Rectangle    drawingPosition = this.textArea.TextView.DrawingPosition;
                TextLocation logicalPosition = textView.GetLogicalPosition(x, y - drawingPosition.Y);
                this.textArea.Caret.Position = logicalPosition;
                this.textArea.SetDesiredColumn();
            }
        }
        private void OnMouseDown(object sender, MouseEventArgs e)
        {
            this.textArea.mousepos = e.Location;
            Point location = e.Location;

            if (this.dodragdrop)
            {
                return;
            }
            if (this.doubleclick)
            {
                this.doubleclick = false;
                return;
            }
            if (this.textArea.TextView.DrawingPosition.Contains(location.X, location.Y))
            {
                this.gotmousedown = true;
                this.textArea.SelectionManager.selectFrom.@where = 2;
                this.button = e.Button;
                if (this.button == MouseButtons.Left && e.Clicks == 2)
                {
                    int num  = Math.Abs(this.lastmousedownpos.X - e.X);
                    int num1 = Math.Abs(this.lastmousedownpos.Y - e.Y);
                    if (num <= SystemInformation.DoubleClickSize.Width && num1 <= SystemInformation.DoubleClickSize.Height)
                    {
                        this.DoubleClickSelectionExtend();
                        this.lastmousedownpos = new Point(e.X, e.Y);
                        if (this.textArea.SelectionManager.selectFrom.@where == 1 && !this.minSelection.IsEmpty && !this.maxSelection.IsEmpty && this.textArea.SelectionManager.SelectionCollection.Count > 0)
                        {
                            this.textArea.SelectionManager.SelectionCollection[0].StartPosition = this.minSelection;
                            this.textArea.SelectionManager.SelectionCollection[0].EndPosition   = this.maxSelection;
                            this.textArea.SelectionManager.SelectionStart = this.minSelection;
                            this.minSelection = TextLocation.Empty;
                            this.maxSelection = TextLocation.Empty;
                        }
                        return;
                    }
                }
                this.minSelection = TextLocation.Empty;
                this.maxSelection = TextLocation.Empty;
                Point point  = new Point(e.X, e.Y);
                Point point1 = point;
                this.mousedownpos     = point;
                this.lastmousedownpos = point1;
                if (this.button == MouseButtons.Left)
                {
                    TextView   textView               = this.textArea.TextView;
                    int        x                      = location.X - this.textArea.TextView.DrawingPosition.X;
                    int        y                      = location.Y;
                    Rectangle  drawingPosition        = this.textArea.TextView.DrawingPosition;
                    FoldMarker foldMarkerFromPosition = textView.GetFoldMarkerFromPosition(x, y - drawingPosition.Y);
                    if (foldMarkerFromPosition != null && foldMarkerFromPosition.IsFolded)
                    {
                        if (this.textArea.SelectionManager.HasSomethingSelected)
                        {
                            this.clickedOnSelectedText = true;
                        }
                        TextLocation textLocation  = new TextLocation(foldMarkerFromPosition.StartColumn, foldMarkerFromPosition.StartLine);
                        TextLocation textLocation1 = new TextLocation(foldMarkerFromPosition.EndColumn, foldMarkerFromPosition.EndLine);
                        this.textArea.SelectionManager.SetSelection(new DefaultSelection(this.textArea.TextView.Document, textLocation, textLocation1));
                        this.textArea.Caret.Position = textLocation;
                        this.textArea.SetDesiredColumn();
                        this.textArea.Focus();
                        return;
                    }
                    if ((Control.ModifierKeys & Keys.Shift) != Keys.Shift)
                    {
                        TextView     textView1       = this.textArea.TextView;
                        int          x1              = location.X - this.textArea.TextView.DrawingPosition.X;
                        int          y1              = location.Y;
                        Rectangle    rectangle       = this.textArea.TextView.DrawingPosition;
                        TextLocation logicalPosition = textView1.GetLogicalPosition(x1, y1 - rectangle.Y);
                        this.clickedOnSelectedText = false;
                        int offset = this.textArea.Document.PositionToOffset(logicalPosition);
                        if (!this.textArea.SelectionManager.HasSomethingSelected || !this.textArea.SelectionManager.IsSelected(offset))
                        {
                            this.textArea.SelectionManager.ClearSelection();
                            if (location.Y > 0 && location.Y < this.textArea.TextView.DrawingPosition.Height)
                            {
                                TextLocation textLocation2 = new TextLocation()
                                {
                                    Y = Math.Min(this.textArea.Document.TotalNumberOfLines - 1, logicalPosition.Y),
                                    X = logicalPosition.X
                                };
                                this.textArea.Caret.Position = textLocation2;
                                this.textArea.SetDesiredColumn();
                            }
                        }
                        else
                        {
                            this.clickedOnSelectedText = true;
                        }
                    }
                    else
                    {
                        this.ExtendSelectionToMouse();
                    }
                }
                else if (this.button == MouseButtons.Right)
                {
                    TextView     textView2        = this.textArea.TextView;
                    int          x2               = location.X - this.textArea.TextView.DrawingPosition.X;
                    int          y2               = location.Y;
                    Rectangle    drawingPosition1 = this.textArea.TextView.DrawingPosition;
                    TextLocation logicalPosition1 = textView2.GetLogicalPosition(x2, y2 - drawingPosition1.Y);
                    int          offset1          = this.textArea.Document.PositionToOffset(logicalPosition1);
                    if (!this.textArea.SelectionManager.HasSomethingSelected || !this.textArea.SelectionManager.IsSelected(offset1))
                    {
                        this.textArea.SelectionManager.ClearSelection();
                        if (location.Y > 0 && location.Y < this.textArea.TextView.DrawingPosition.Height)
                        {
                            TextLocation textLocation3 = new TextLocation()
                            {
                                Y = Math.Min(this.textArea.Document.TotalNumberOfLines - 1, logicalPosition1.Y),
                                X = logicalPosition1.X
                            };
                            this.textArea.Caret.Position = textLocation3;
                            this.textArea.SetDesiredColumn();
                        }
                    }
                }
            }
            this.textArea.Focus();
        }