Beispiel #1
0
		//=========================================================================================
		internal string GetText(TextPoint start, TextPoint end)
		{
			if (start > end)
			{
				TextPoint temp = start;
				start = end;
				end = temp;
			}
			if (start.Line == end.Line)
				return this.Lines[start.Line].Text.Substring(start.Char, end.Char - start.Char);
			else
			{
				System.Text.StringBuilder sb = new System.Text.StringBuilder();

				string sLine = this.Lines[start.Line].Text;
				sb.AppendLine(sLine.Substring(start.Char, sLine.Length - start.Char));

				for (int i = start.Line + 1; i < end.Line; i++)
					sb.AppendLine(this.Lines[i].Text);

				sb.AppendLine(this.Lines[end.Line].Text.Substring(0, end.Char));

				return sb.ToString();
			}
		}
		//=========================================================================================
		private void DrawSpanBackground(Graphics g, TextPoint start, TextPoint end, Brush brush, Pen pen)
		{
			if (start.Line != end.Line)
			{
				//first selected line
				int iLastCol = TextCaret.GetLastCol(this.Viewer.Document[start.Line].Text, this.Viewer._TabSize);
				this.DrawLineSpanBackground(g, start.Line, start.Col, iLastCol - start.Col, brush, null);
				//intermediate selected lines
				for (int i = start.Line + 1; i < end.Line; i++)
				{
					iLastCol = TextCaret.GetLastCol(this.Viewer.Document[i].Text, this.Viewer._TabSize);
					this.DrawLineSpanBackground(g, i, 0, iLastCol + 1, brush, null);
				}
				//last selected line
				this.DrawLineSpanBackground(g, end.Line, 0, end.Col, brush, null);
			}
			//if there some selected symbols
			else if (start.Col != end.Col)
				this.DrawLineSpanBackground(g, start.Line, start.Col, end.Col - start.Col, brush, pen);
		}
		//=========================================================================================
		/// <summary>Compare specified position with some expected.</summary>
		private void AssertPoint(TextPoint point, int line, int chr, int col)
		{
			Assert.AreEqual(point.ToString(), string.Format("Ln:{0}, col:{1}, ch:{2}", line, col, chr));
		}
		//=========================================================================================
		/// <summary>Compare specified position with some expected.</summary>
		private void AssertPoint(TextPoint point, int line, int chr)
		{
			Assert.AreEqual(point.Line, line);
			Assert.AreEqual(point.Char, chr);
		}
		//=========================================================================================
		protected override void OnMouseDown(MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left)
			{
                var oSelectionPos = this.SelectionStart;
                TextPoint pos = this.GetTextPointByXY(e.Location);
				this.Caret.MoveToPos(pos.Line, pos.Col, true);
                if ((Control.ModifierKeys & Keys.Shift) == 0)
                    this.SelectionStart = this.Caret.Point;
                else
                    this.SelectionStart = oSelectionPos;
				this.Caret.Blink = true;
				this.Invalidate(false);
				this.Capture = true;
			}
			else if (e.Button == MouseButtons.Right && !this.Viewer.SelectionExists)
			{
				TextPoint pos = this.GetTextPointByXY(e.Location);
				this.Caret.MoveToPos(pos.Line, pos.Col, true);
				this.SelectionStart = this.Caret.Point;
				this.Caret.Blink = true;
				this.Invalidate(false);
			}
			base.OnMouseDown(e);
		}
		//=========================================================================================
		public Point GetXYByTextPoint(TextPoint pos)
		{
			int x = (pos.Col - this.FirstVisibleCol) * this.Viewer.CharWidth + this.Viewer.MarginWidth;
			int y = (pos.Line - this.FirstVisibleRow) * this.Viewer.CharHeight;
			return new Point(x, y);
		}
Beispiel #7
0
		//=========================================================================================
		#region Служебный код
		//=========================================================================================
		/// <summary>Move caret to the specified position and generate event if it's need</summary>
		void SetCaretPos(int line, int chr, int col, bool changeWantedCol, bool clearSelection)
		{
			bool bPosChanged = this._Point.Line != line || this._Point.Char != chr;
			if (bPosChanged)
				this._Point = new TextPoint(line, col, chr);

			if (clearSelection)
				this.Parent.SelectionStart = this._Point;
			if (bPosChanged)
			{
				this._CurrentToken_Is_Valid = false;
				//Generate OnChangeSelection event
				this.Parent.Viewer.OnChangeSelection();
			}
			if (changeWantedCol)
				this._WantedCol = col;
		}
Beispiel #8
0
		//=========================================================================================
		public static TextPoint Max(TextPoint first, TextPoint second)
		{
			return first.CompareTo(second) >= 0 ? first : second;
		}
Beispiel #9
0
		//=========================================================================================
        internal int GetTextIndexByTextPoint(TextPoint textPoint)
        {
            int iTextIndex = textPoint.Char;

            for (int i = 0; i < textPoint.Line; i++)
                iTextIndex += this.Document[i].Text.Length + "\r\n".Length;

            return iTextIndex;

        }