Ejemplo n.º 1
0
        public void MouseDrag(Point P)
        {
            DocumentLocation dl;

            if (P.Y < 0 || P.Y > textArea.Bottom)
            {
                lastMouseDragPoint = P;

                if (!dragDelayOK)
                {
                    return;
                }

                dragDelayOK = false;

                DocumentLocation dl2 = (selectAnchor == Selection.Start) ? Selection.End : Selection.Start;

                int l  = dl2.LineNumber;
                int sl = doc[l].SubLineNum(dl2.ColumnNumber);

                if (doc.Offset((P.Y < 0 ? -1 : 1), ref l, ref sl))
                {
                    dl = new DocumentLocation(l, doc[l].SubLineStart(sl) + Math.Min(doc[l].GetSubLines(false)[sl].Length, doc.XCoord(dl2)));
                }
                else
                {
                    return;
                }

                Clock.Update(ref mouseDragTimer, makeDragDelayOK, OFF_SCREEN_DRAG_DELAY, false);
            }
            else
            {
                if (mouseDragTimer != Clock.NULL_ALARM)
                {
                    Clock.RemoveAlarm(mouseDragTimer);
                }

                mouseDragTimer = Clock.NULL_ALARM;
                dragDelayOK    = true;
                dl             = getDocLocFromScreenXY(getScreenXYFromPixel(P));
            }

            if (selectAnchor == null)
            {
                if (dragging)
                {
                    CaretDocLoc = dl;
                    setCaretLocation(true);
                }
                else if (!Selection.IsEmpty && Selection.Contains(dl))
                {
                    dragging    = true;
                    CaretDocLoc = dl;
                    setCaretLocation(true);
                    parent.Cursor = Cursors.Hand;
                    dragDelayOK   = true;
                }
                else
                {
                    dragDelayOK  = true;
                    selectAnchor = dl;
                }
            }
            else
            {
                Selection = new DocumentRange(selectAnchor, dl);
                if (!Selection.IsEmpty)
                {
                    CaretDocLoc = (Selection.Start == selectAnchor) ? Selection.End : Selection.Start;
                    setCaretLocation(true);
                }
            }
            setCaretLocation(true);
            parent.Invalidate();
        }
Ejemplo n.º 2
0
 public void MakeVisible(DocumentRange DR)
 {
     makeVisible(DR.End);
     makeVisible(DR.Start);
 }
Ejemplo n.º 3
0
 public DocumentRange EnsureValid(DocumentRange DR)
 {
     return(new DocumentRange(EnsureValid(DR.Start), EnsureValid(DR.End)));
 }
Ejemplo n.º 4
0
        private void move(MoveType MoveType, bool Select)
        {
            DocumentLocation old = CaretDocLoc;

            if (!Select)
            {
                Selection = DocumentRange.Empty;
            }

            undoManager.ClosePackage();

            switch (MoveType)
            {
            case MoveType.Left:
                CaretDocLoc = doc.GetPreviousVisibleLocation(CaretDocLoc);
                break;

            case MoveType.Right:
                CaretDocLoc = doc.GetNextVisibleLocation(CaretDocLoc);
                break;

            case MoveType.Up:
                if (CaretXY == invalidXY)
                {
                    setCaretLocation(true);
                }
                CaretDocLoc = getDocLocFromScreenXY(new Point(PreferredX, CaretXY.Y - 1));
                break;

            case MoveType.Down:
                if (CaretXY == invalidXY)
                {
                    setCaretLocation(true);
                }
                CaretDocLoc = getDocLocFromScreenXY(new Point(PreferredX, CaretXY.Y + 1));
                break;

            case MoveType.RightWord:
                CaretDocLoc = doc.GetNextWord(CaretDocLoc);
                break;

            case MoveType.LeftWord:
                CaretDocLoc = doc.GetPreviousWord(CaretDocLoc);
                break;

            case MoveType.Home:
                Line l   = doc[CaretDocLoc.LineNumber];
                int  sln = l.SubLineNum(caretDocLoc.ColumnNumber);
                int  x   = l.GetSubLines(false)[sln].FirstNonWSChar();

                if (CaretDocLoc.ColumnNumber == 0 && x > 0)
                {
                    CaretDocLoc = new DocumentLocation(CaretDocLoc.LineNumber, x);
                }
                else if (x > 0 && x < CaretDocLoc.ColumnNumber - l.BeginningOfSubLine(sln))
                {
                    CaretDocLoc = new DocumentLocation(CaretDocLoc.LineNumber, x + l.BeginningOfSubLine(sln));
                }
                else
                {
                    CaretDocLoc = new DocumentLocation(CaretDocLoc.LineNumber, l.BeginningOfSubLine(sln));
                }
                break;

            case MoveType.End:
                CaretDocLoc = new DocumentLocation(CaretDocLoc.LineNumber, doc[CaretDocLoc.LineNumber].EndOfSubLine(doc[CaretDocLoc.LineNumber].SubLineNum(CaretDocLoc.ColumnNumber)));
                break;

            case MoveType.PageUp:
                if (CaretXY.X < 0)
                {
                    makeVisible(CaretDocLoc);
                }
                {
                    Point p = CaretXY;
                    p.X = PreferredX;
                    if (!offset(-NumVisibleLines))
                    {
                        p.Y = 0;
                    }
                    CaretDocLoc = getDocLocFromScreenXY(p);
                }
                break;

            case MoveType.PageDown:
                if (CaretXY.X < 0)
                {
                    makeVisible(CaretDocLoc);
                }
                {
                    Point p = CaretXY;
                    p.X = PreferredX;

                    if (offset(NumVisibleLines))
                    {
                        CaretDocLoc = getDocLocFromScreenXY(p);
                    }
                    else
                    {
                        CaretDocLoc = new DocumentLocation(doc, doc.NumLines - 1, doc[doc.NumLines - 1].NumVisibleSubLines - 1, PreferredX);
                    }
                }
                break;
            }

            if (Select)
            {
                if (selectionAnchor == null)
                {
                    selectionAnchor = old;
                }
                Selection = new DocumentRange(selectionAnchor, CaretDocLoc);
            }
            setCaretLocation(true);
            parent.Invalidate();
        }
Ejemplo n.º 5
0
 static DocumentRange()
 {
     Empty = new DocumentRange(DocumentLocation.BOF, DocumentLocation.BOF);
 }