Exemple #1
0
		HexMouseLocation(HexViewLine hexViewLine, int position, Point point) {
			if (hexViewLine == null)
				throw new ArgumentNullException(nameof(hexViewLine));
			HexViewLine = hexViewLine;
			Position = position;
			Point = point;
		}
			public override VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement) {
				var transform = removeExtraTextLineVerticalPixels ?
					new VSTF.LineTransform(0, 0, line.DefaultLineTransform.VerticalScale, line.DefaultLineTransform.Right) :
					line.DefaultLineTransform;
				foreach (var source in lineTransformSources)
					transform = VSTF.LineTransform.Combine(transform, source.GetLineTransform(line, yPosition, placement));
				return transform;
			}
		/// <summary>
		/// Move caret to a line
		/// </summary>
		/// <param name="hexLine">Line</param>
		/// <param name="horizontalOffset">Horizontal offset</param>
		/// <param name="extendSelection">true to extend the selection</param>
		public void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection) =>
			MoveCaret(hexLine, horizontalOffset, extendSelection, HexMoveToFlags.CaptureHorizontalPosition);
		/// <summary>
		/// Move caret to a line
		/// </summary>
		/// <param name="hexLine">Line</param>
		/// <param name="horizontalOffset">Horizontal offset</param>
		/// <param name="extendSelection">true to extend the selection</param>
		/// <param name="flags">Flags</param>
		public abstract void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection, HexMoveToFlags flags);
Exemple #5
0
		Rect GetCaretRect(HexViewLine line, bool drawOverwriteMode, HexColumnType column, HexCell cell, int cellPosition) {
			if (cell == null)
				return new Rect();

			int linePosition = cell.CellSpan.Start + Math.Max(0, Math.Min(cell.CellSpan.Length - 1, cellPosition));
			if (hexCaret.CurrentPosition.ActiveColumn != column) {
				var r = ToRect(line.GetNormalizedTextBounds(cell.CellSpan));
				return new Rect(r.X, r.Bottom - INACTIVE_CARET_HEIGHT, r.Width, INACTIVE_CARET_HEIGHT);
			}
			else if (drawOverwriteMode) {
				var textBounds = line.GetExtendedCharacterBounds(linePosition);
				var left = textBounds.Left;
				var top = line.TextTop;
				var width = textBounds.Width;
				var height = line.TextHeight;
				return new Rect(left, top, width, height);
			}
			else {
				double left;
				if (linePosition != 0 && linePosition <= line.BufferLine.Text.Length)
					left = line.GetExtendedCharacterBounds(linePosition - 1).Trailing;
				else
					left = line.GetExtendedCharacterBounds(linePosition).Leading;
				var top = line.TextTop;
				var width = SystemParameters.CaretWidth;
				var height = line.TextHeight;
				return new Rect(left, top, width, height);
			}
		}
		/// <summary>
		/// Selects the line
		/// </summary>
		/// <param name="viewLine">Line</param>
		/// <param name="extendSelection">true to extend the selection</param>
		public abstract void SelectLine(HexViewLine viewLine, bool extendSelection);
Exemple #7
0
		/// <summary>
		/// Moves the caret to a new position
		/// </summary>
		/// <param name="hexLine">Line</param>
		/// <param name="xCoordinate">X coordinate</param>
		/// <returns></returns>
		public abstract HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate);
		IEnumerable<KeyValuePair<HexColumnType, Rect>> GetRectanglePositions(HexViewLine line) {
			var column = wpfHexView.Caret.Position.Position.ActiveColumn;
			if (!line.BufferLine.IsColumnPresent(column))
				yield break;
			var span = line.BufferLine.GetSpan(column, onlyVisibleCells: false);
			var rect = GetBounds(line.GetNormalizedTextBounds(span));
			if (rect == null || rect.Value.Width <= 0)
				yield break;
			yield return new KeyValuePair<HexColumnType, Rect>(column, new Rect(rect.Value.X, wpfHexView.ViewportTop, rect.Value.Width, wpfHexView.ViewportHeight));
		}
Exemple #9
0
		/// <summary>
		/// Gets the slection on a line
		/// </summary>
		/// <param name="line">Line</param>
		/// <returns></returns>
		public abstract IEnumerable<VST.Span> GetSelectionOnHexViewLine(HexViewLine line);
Exemple #10
0
		bool Intersects(HexBufferSpan fullSpan, HexViewLine line, Rect rect) {
			var span = fullSpan.Intersection(line.BufferSpan);
			if (span == null || span.Value.Length == 0)
				return false;
			var allBounds = line.GetNormalizedTextBounds(span.Value, HexSpanSelectionFlags.Selection);
			if (allBounds.Count == 0)
				return false;
			double left = double.MaxValue, right = double.MinValue, top = double.MaxValue, bottom = double.MinValue;
			foreach (var bounds in allBounds) {
				left = Math.Min(left, bounds.Left);
				right = Math.Max(right, bounds.Right);
				top = Math.Min(top, bounds.TextTop);
				bottom = Math.Max(bottom, bounds.TextBottom);
			}
			left -= wpfHexView.ViewportLeft;
			top -= wpfHexView.ViewportTop;
			right -= wpfHexView.ViewportLeft;
			bottom -= wpfHexView.ViewportTop;
			bool b = left <= right && top <= bottom;
			Debug.Assert(b);
			if (!b)
				return false;
			var r = new Rect(left, top, right - left, bottom - top);
			return r.IntersectsWith(rect);
		}
		public override void MoveCaret(HexViewLine hexLine, double horizontalOffset, bool extendSelection, HexMoveToFlags flags) {
			if (hexLine == null)
				throw new ArgumentNullException(nameof(hexLine));

			var anchorPoint = GetAnchorPositionOrCaretIfNoSelection();
			Caret.MoveTo(hexLine, horizontalOffset, flags);
			if (extendSelection)
				SelectToCaret(anchorPoint);
			else
				Selection.Clear();
		}
Exemple #12
0
		public override IEnumerable<VST.Span> GetSelectionOnHexViewLine(HexViewLine line) {
			if (line == null)
				throw new ArgumentNullException(nameof(line));
			if (line.BufferLine.LineProvider != HexView.BufferLines)
				throw new ArgumentException();

			foreach (var info in line.BufferLine.GetSpans(StreamSelectionSpan, SelectionFlags)) {
				if (info.TextSpan.Length != 0)
					yield return info.TextSpan;
			}
		}
		public override void SelectLine(HexViewLine viewLine, bool extendSelection) {
			if (viewLine == null)
				throw new ArgumentNullException(nameof(viewLine));

			HexBufferPoint anchorPoint, activePoint;
			var lineStart = viewLine.BufferStart;
			var lineEnd = viewLine.BufferEnd;

			if (Selection.IsEmpty || !extendSelection) {
				anchorPoint = lineStart;
				activePoint = lineEnd;
			}
			else {
				var anchorSpan = SelectionUtilities.GetLineAnchorSpan(Selection);
				if (anchorSpan.Start <= viewLine.BufferStart) {
					anchorPoint = anchorSpan.Start;
					activePoint = lineEnd;
				}
				else {
					anchorPoint = anchorSpan.End;
					activePoint = lineStart;
				}
			}
			Selection.Select(anchorPoint, activePoint, alignPoints: true);
			// This moves the caret outside the selection but it matches the text editor when
			// full lines are selected.
			Caret.MoveTo(activePoint);
			Caret.EnsureVisible();
		}
		IList<VSTF.TextBounds> GetTextBounds(HexViewLine line) {
			if (lineSpan.IsTextSpan) {
				if (lineSpan.TextSpan.Value.Length == 0) {
					if (line.BufferSpan.Contains(lineSpan.BufferSpan)) {
						var bounds = line.GetCharacterBounds(lineSpan.TextSpan.Value.Start);
						// It's just a point, so use zero width
						bounds = new VSTF.TextBounds(bounds.Leading, bounds.Top, 0, bounds.Height, bounds.TextTop, bounds.TextHeight);
						return new VSTF.TextBounds[] { bounds };
					}
					return Array.Empty<VSTF.TextBounds>();
				}
				else
					return line.GetNormalizedTextBounds(lineSpan);
			}
			else {
				var fullSpan = lineSpan.BufferSpan;
				if (fullSpan.Length == 0) {
					if (line.BufferSpan.Contains(fullSpan))
						return line.GetNormalizedTextBounds(fullSpan, lineSpan.SelectionFlags.Value);
					return Array.Empty<VSTF.TextBounds>();
				}
				else
					return line.GetNormalizedTextBounds(lineSpan);
			}
		}
		public void SetLine(HexViewLine line, double width) {
			if (line == null)
				throw new ArgumentNullException(nameof(line));
			var newRect = new Rect(PEN_THICKNESS / 2, PEN_THICKNESS / 2, Math.Max(0, width - PEN_THICKNESS), Math.Max(0, line.TextHeight + HexFormattedLineImpl.DEFAULT_BOTTOM_SPACE - PEN_THICKNESS));
			if (geometry != null && newRect == geometryRect)
				return;
			geometryRect = newRect;
			if (geometryRect.Height == 0 || geometryRect.Width == 0)
				geometry = null;
			else {
				geometry = new RectangleGeometry(geometryRect);
				if (geometry.CanFreeze)
					geometry.Freeze();
			}
			InvalidateVisual();
		}
 /// <summary>
 /// Calculates the line transform for a given line of formatted text
 /// </summary>
 /// <param name="line">Line</param>
 /// <param name="yPosition">Y position</param>
 /// <param name="placement">Placement</param>
 /// <returns></returns>
 public abstract VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement);
Exemple #17
0
			public override VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement) =>
				owner.LineTransformProvider.GetLineTransform(line, yPosition, placement);
		/// <summary>
		/// Calculates the line transform for a given line of formatted text
		/// </summary>
		/// <param name="line">Line</param>
		/// <param name="yPosition">Y position</param>
		/// <param name="placement">Placement</param>
		/// <returns></returns>
		public abstract VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement);
Exemple #19
0
		/// <summary>
		/// Moves the caret to a new position
		/// </summary>
		/// <param name="hexLine">Line</param>
		/// <param name="xCoordinate">X coordinate</param>
		/// <param name="flags">Flags</param>
		/// <returns></returns>
		public abstract HexCaretPosition MoveTo(HexViewLine hexLine, double xCoordinate, HexMoveToFlags flags);
Exemple #20
0
			public LineInfo(HexViewLine hexViewLine, List<IconInfo> icons) {
				if (hexViewLine == null)
					throw new ArgumentNullException(nameof(hexViewLine));
				if (icons == null)
					throw new ArgumentNullException(nameof(icons));
				Line = hexViewLine;
				Icons = icons;
			}
Exemple #21
0
		void AddLine(Dictionary<object, LineInfo> newInfos, HexViewLine line) {
			var wpfLine = line as WpfHexViewLine;
			Debug.Assert(wpfLine != null);
			if (wpfLine == null)
				return;
			var info = new LineInfo(line, CreateIconInfos(wpfLine));
			newInfos.Add(line.IdentityTag, info);
			foreach (var iconInfo in info.Icons)
				childCanvases[iconInfo.Order].Children.Add(iconInfo.Element);
		}
Exemple #22
0
		void RaiseLayoutChanged(double effectiveViewportWidth, double effectiveViewportHeight, HexViewLine[] newOrReformattedLines, HexViewLine[] translatedLines) {
			if (IsClosed)
				return;
			Debug.Assert(!raisingLayoutChanged);
			raisingLayoutChanged = true;
			var newViewState = new HexViewState(this, effectiveViewportWidth, effectiveViewportHeight);
			var layoutChangedEventArgs = new HexViewLayoutChangedEventArgs(oldViewState, newViewState, newOrReformattedLines, translatedLines);
			LayoutChanged?.Invoke(this, layoutChangedEventArgs);
			oldViewState = newViewState;
			foreach (var p in visiblePhysicalLines) {
				foreach (var l in p.Lines) {
					l.SetChange(VSTF.TextViewLineChange.None);
					l.SetDeltaY(0);
				}
			}
			Debug.Assert(raisingLayoutChanged);
			raisingLayoutChanged = false;
			mouseHoverHelper.OnLayoutChanged();
			if (ShouldQueueSpaceReservationStackRefresh(layoutChangedEventArgs))
				QueueSpaceReservationStackRefresh();
		}
Exemple #23
0
		/// <summary>
		/// Moves the caret to a new position
		/// </summary>
		/// <param name="hexLine">Line</param>
		/// <returns></returns>
		public abstract HexCaretPosition MoveTo(HexViewLine hexLine);