public SingleLineInputField(ICaret caret,
                             IInputEventProcessor inputEventProcessor,
                             IInputFieldController controller,
                             ITextComponentWrapper editableText
                             ) : base(caret, inputEventProcessor, controller, editableText)
 {
 }
 protected override void DrawCaret(ICaret caret, Color color, ITextComponentWrapper text, Vector2 offset)
 {
     using (var helper = new VertexHelper())
     {
         caret.Draw(CalculateCaretDrawRect(text, offset, caret.GetIndex() - _drawStart), color, helper);
     }
 }
Exemple #3
0
 public VrInputFieldImpl(ICaret caret,
                         IInputEventProcessor inputEventProcessor,
                         IInputFieldController controller)
 {
     _controller          = controller;
     _caret               = caret;
     _inputEventProcessor = inputEventProcessor;
 }
 public MultiLineInputFieldImpl(
     ICaret caret,
     IInputEventProcessor inputEventProcessor,
     IInputFieldController controller,
     ITextComponentWrapper text)
     : base(caret, inputEventProcessor, controller, text)
 {
 }
 public TextViewDocument(ITextDocument document, ICaret caret, IClassifier classifier, IClassificationStyler classificationStyler)
 {
     _document = document;
     _classifier = classifier;
     _classificationStyler = classificationStyler;
     Buffer.Changed += OnBufferChange;
     Caret = caret;
 }
Exemple #6
0
 public TextViewDocument(ITextDocument document, ICaret caret, IClassifier classifier, IClassificationStyler classificationStyler)
 {
     _document                      = document;
     _classifier                    = classifier;
     _classificationStyler          = classificationStyler;
     _classificationStyler.Changed += (Sender, Args) => RemoveCachedLinesFrom(0);
     Buffer.Changed                += OnBufferChange;
     Caret = caret;
 }
		public TextViewDocument(ITextDocument document, ICaret caret, IClassifier classifier, IClassificationStyler classificationStyler)
		{
			_document = document;
			_classifier = classifier;
			_classificationStyler = classificationStyler;
			_classificationStyler.Changed += (Sender, Args) => RemoveCachedLinesFrom(0);
			Buffer.Changed += OnBufferChange;
			Caret = caret;
		}
        protected override void DrawSelection(ICaret caret, Color color, ITextComponentWrapper text, Vector2 offset)
        {
            int index          = LocalIndex();
            int selectionIndex = LocalSelectionIndex(text);

            using (var helper = new VertexHelper())
            {
                Caret.Draw(CalculateCaretDrawRect(text, offset, index, selectionIndex), color, helper);
            }
        }
Exemple #9
0
 public AbstractInputField(ICaret caret,
                           IInputEventProcessor inputEventProcessor,
                           IInputFieldController controller,
                           ITextComponentWrapper text)
 {
     _editableText        = text;
     _caret               = caret;
     _inputEventProcessor = inputEventProcessor;
     _controller          = controller;
 }
        private ICaret CreateCaret()
        {
            GameObject caretObj = new GameObject(transform.name + " Caret", typeof(DefaultCaret));

            caretObj.hideFlags = HideFlags.DontSave;
            caretObj.transform.SetParent(_textComponent.transform.parent);
            ICaret caret = caretObj.GetComponent <ICaret>();

            caret.InputFieldController = this;
            return(caret);
        }
        protected override void DrawSelection(ICaret caret, Color color, ITextComponentWrapper text, Vector2 offset)
        {
            var lines = CalculateSelectionRects(caret, text, offset);

            using (var helper = new VertexHelper())
            {
                foreach (var rect in lines)
                {
                    caret.Draw(rect, color, helper);
                }
            }
        }
Exemple #12
0
        public QuickFixIndicator(Control parent, ICaret caret)
        {
            this.parent = parent;
            this.caret  = caret;

            imageList            = new ImageList();
            imageList.ImageSize  = new Size(14, 14);
            imageList.ColorDepth = ColorDepth.Depth32Bit;

            LoadImage("Bulb.png");
            LoadImage("BulbArrow.png");
        }
        public static string TextForSelection(this ICaret caret, ITextDocument doc)
        {
            if (caret.MaximumOffset != doc.TextLength)
            {
                throw new ArgumentException();
            }

            var start = Math.Min(caret.SelectionStartOffset, caret.SelectionEndOffset);
            var end   = Math.Max(caret.SelectionStartOffset, caret.SelectionEndOffset);

            return(doc.TextAt(start, end - start));
        }
        protected override string ProcessText(ITextComponentWrapper editableText, ICaret caret)
        {
            // truncate text to display within the bounds of text rect.
            Vector2 textRectExtents = editableText.DisplayRect.size;

            float width = 0;

            if (caret.GetIndex() > _drawEnd || (caret.GetIndex() == TextValue.Length && _drawStart > 0))
            {
                _drawEnd   = caret.GetIndex();
                _drawStart = _drawEnd - 1;
                while (width < textRectExtents.x && _drawStart >= 0)
                {
                    width += editableText.CharWidth(_drawStart--);
                }

                if (width >= textRectExtents.x)
                {
                    _drawStart++;
                }

                _drawStart++;
            }
            else
            {
                if (caret.GetIndex() < _drawStart)
                {
                    _drawStart = caret.GetIndex();
                }

                _drawEnd = _drawStart;
                while (width < textRectExtents.x && _drawEnd < TextValue.Length)
                {
                    width += editableText.CharWidth(_drawEnd++);
                }

                if (width >= textRectExtents.x)
                {
                    _drawEnd--;
                }
            }

            _drawStart = Mathf.Clamp(_drawStart, 0, TextValue.Length);
            _drawEnd   = Mathf.Clamp(_drawEnd, 0, TextValue.Length);
            return(TextValue.Substring(_drawStart, _drawEnd - _drawStart));
        }
        private List <Rect> CalculateSelectionRects(ICaret caret, ITextComponentWrapper text, Vector2 offset)
        {
            List <Rect> highlightRects = new List <Rect>();

            int start = Mathf.Min(caret.GetIndex(), caret.GetSelectionIndex()) - _drawStart;

            start = Mathf.Clamp(start, 0, text.DisplayedTextLength);
            int end = Mathf.Max(caret.GetIndex(), caret.GetSelectionIndex()) - _drawStart;

            end = Mathf.Clamp(end, 0, text.DisplayedTextLength);

            int startLine = text.GetLineByCharIndex(start);
            int endLine   = text.GetLineByCharIndex(end);

            if (startLine == endLine)
            {
                highlightRects.Add(HightedLineRect(start, end, text.LineHeight(startLine), text));
            }
            else
            {
                int currentLineEndIndex = text.LineEndIndex(startLine);
                highlightRects.Add(HightedLineRect(start, currentLineEndIndex, text.LineHeight(startLine), text));

                while (startLine < endLine - 1)
                {
                    startLine++;
                    highlightRects.Add(HightedLineRect(
                                           text.LineStartIndex(startLine),
                                           text.LineEndIndex(startLine),
                                           text.LineHeight(startLine),
                                           text));
                }

                highlightRects.Add(HightedLineRect(
                                       text.LineStartIndex(endLine), end, text.LineHeight(endLine), text));
            }
            return(highlightRects);
        }
 public static void SelectAll(this ICaret caret)
 {
     caret.MoveTo(0);
     caret.Select(caret.MaximumOffset);
 }
        protected override string ProcessText(ITextComponentWrapper text, ICaret caret)
        {
            Vector2 extents = text.DisplayRect.size;

            int caretLine = text.GetLineByCharIndex(caret.GetIndex());

            if (caret.GetIndex() > _drawEnd)
            {
                _drawEnd = text.LineEndIndex(caretLine);
                float bottomY = text.LineTop(caretLine) - text.LineHeight(caretLine);
                // TODO: Remove interline spacing on last line.
                int startLine = caretLine;
                while (startLine > 0)
                {
                    float topY = text.LineTop(startLine - 1);
                    if (topY - bottomY > extents.y)
                    {
                        break;
                    }
                    startLine--;
                }
                _drawStart = text.LineStartIndex(startLine);
            }
            else
            {
                if (caret.GetIndex() < _drawStart)
                {
                    _drawStart = text.LineStartIndex(caretLine);
                }

                int startLine = text.GetLineByCharIndex(_drawStart);
                int endLine   = startLine;

                float topY    = text.LineTop(startLine);
                float bottomY = text.LineTop(endLine) - text.LineHeight(endLine);

                // TODO: Remove interline spacing on last line.

                while (endLine < text.LineCount - 1)
                {
                    bottomY = text.LineTop(endLine + 1) - text.LineHeight(endLine + 1);
                    // TODO: Remove interline spacing on last line.
                    if (topY - bottomY > extents.y)
                    {
                        break;
                    }
                    ++endLine;
                }

                _drawEnd = text.LineEndIndex(endLine);

                while (startLine > 0)
                {
                    topY = text.LineTop(startLine - 1);
                    if (topY - bottomY > extents.y)
                    {
                        break;
                    }

                    startLine--;
                }

                _drawStart = text.LineStartIndex(startLine);
            }
            return(TextValue.Substring(_drawStart, _drawEnd - _drawStart));
        }
Exemple #18
0
        /// <summary>
        /// The main control for XEditNet applications.
        /// </summary>
        // TODO: D: add remarks section
        public XEditNetCtrl()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            //			if ( !this.DesignMode )
            //			{
            //				Application.EnableVisualStyles();
            //				Application.DoEvents();
            //			}

            SetStyle(ControlStyles.DoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);

            nodocWnd=new NoDocumentControl();
            nodocWnd.Parent=this;

            findWindow=new FindPopup(this);

            if ( this.DesignMode )
                return;

            caret=grFactory.CreateCaret(this);
            caret.Visible=true;
            quickFixIndicator=new QuickFixIndicator(this, caret);

            Stylesheet=new Stylesheet();
            undoManager=new UndoManager(this);
            commandMapper=CommandMapper.CreateInstance(this);
        }
Exemple #19
0
        private SelectionPoint GetSelectionPoint(Point pt, ref Rectangle caret)
        {
            if ( layoutEngine == null )
                return null;

            if ( pt.Y < 0 )
                pt.Y=0;

            if ( pt.Y >= layoutEngine.BoundingRect.Bottom )
                pt.Y = layoutEngine.BoundingRect.Bottom - 1;

            SelectionPoint sp=null;

            HitTestInfo ht=HitTest(pt, false);
            if ( ht != null )
            {
                sp=ht.SelectionPoint;
                caret=ht.Caret;
                if ( ht.After )
                    sp=selectionManager.NextSelectionPoint(sp);

                if ( !sp.IsValid )
                    Logger.Log("WARN: Invalid selection point!");

                sp=selectionManager.Validate(sp);
            }
            return sp;
        }
Exemple #20
0
 protected abstract void DrawCaret(ICaret caret, Color color, ITextComponentWrapper text, Vector2 offset);
Exemple #21
0
 public Selection(ICaret caret)
 {
     _caret = caret;
     Clear ();
 }
Exemple #22
0
 protected abstract string ProcessText(ITextComponentWrapper text, ICaret caret);
Exemple #23
0
 public Selection(ICaret caret)
 {
     _caret = caret;
     Clear();
 }
 public static bool HasSelection(this ICaret c)
 {
     return(c.SelectionStartOffset != c.SelectionEndOffset);
 }
 public static void ClearSelection(this ICaret caret)
 {
     caret.MoveTo(caret.SelectionEndOffset);
 }
 public CaretNavigator(ICaret caret, ITextComponentWrapper text, IVrInputField inputField)
 {
     _caret       = caret;
     _textWrapper = text;
     _inputField  = inputField;
 }
Exemple #27
0
        public unsafe void Paint(IntPtr hdc, int x, int y, ICaret caret)
        {
            if (this._imeComposition == null)
            {
                return;
            }

            var textRect = this._textView.GetTextRectangle(false);

            var startX = x;
            var startY = y;

            var newLines = new List <int>();

            fixed(char *c = this._imeComposition.Text)
            {
                var clientSize = this._textView.ClientSize;
                var caretY     = -1;
                var caretX     = -1;

                for (var i = 0; i <= this._imeComposition.Text.Length; i++)
                {
                    var s = Size.Empty;

                    var charOffset = newLines.Count == 0
                        ? 0
                        : newLines[newLines.Count - 1];
                    SafeNativeMethods.GetTextExtentPoint32(hdc, c + charOffset, i - charOffset, ref s);

                    if (caretY == -1)
                    {
                        if (i == this._imeComposition.CaretStart)
                        {
                            caretY = newLines.Count * this._textView.LineHeight;
                            caretX = s.Width;
                        }
                    }

                    if (x + s.Width >= clientSize.Width)
                    {
                        newLines.Add(i - 1);
                    }
                }

                var previousBkMode    = SafeNativeMethods.SetBkMode(hdc, NativeConstants.OPAQUE);
                var previousBkColor   = SafeNativeMethods.SetBkColor(hdc, ColorTranslator.ToWin32(Color.WhiteSmoke));
                var previousTextColor = SafeNativeMethods.SetTextColor(hdc, ColorTranslator.ToWin32(Color.Black));

                for (var i = 0; i <= newLines.Count; i++)
                {
                    var start = i > 0 ? newLines[i - 1] : 0;
                    var end   = i < newLines.Count ? newLines[i] : this._imeComposition.Text.Length;

                    SafeNativeMethods.TextOut(hdc, x, y, c + start, end - start);

                    var selStart = Math.Max(this._imeComposition.SelectionStart, start);
                    var selEnd   = Math.Min(this._imeComposition.SelectionEnd, end);

                    if (selStart >= start && selEnd <= end)
                    {
                        var preSize = Size.Empty;

                        if (selStart - start > 0)
                        {
                            SafeNativeMethods.GetTextExtentPoint32(hdc, c, selStart - start, ref preSize);
                        }

                        var selectionSize = Size.Empty;
                        SafeNativeMethods.GetTextExtentPoint32(hdc, c + selStart, selEnd - selStart, ref selectionSize);

                        if (selectionSize.Width > 0)
                        {
                            SafeNativeMethods.MoveToEx(hdc, x + preSize.Width, y + selectionSize.Height, IntPtr.Zero);
                            SafeNativeMethods.LineTo(hdc, x + preSize.Width + selectionSize.Width, y + selectionSize.Height);
                        }
                    }

                    x  = textRect.Left;
                    y += this._textView.LineHeight + 1;
                }

                SafeNativeMethods.SetBkMode(hdc, previousBkMode);
                SafeNativeMethods.SetBkColor(hdc, previousBkColor);
                SafeNativeMethods.SetTextColor(hdc, previousTextColor);

                caret.Render(hdc, startX + caretX, startY + caretY);
            }
        }