Example #1
0
		public HexBufferLineImpl(HexBufferLineFormatter hexBufferLineFormatter, HexPosition lineNumber, ReadOnlyCollection<HexColumnType> columnOrder, HexBufferSpan bufferSpan, HexBytes hexBytes, string text, bool isOffsetColumnPresent, bool isValuesColumnPresent, bool isAsciiColumnPresent, HexPosition logicalOffset, HexCellCollection valueCells, HexCellCollection asciiCells, VST.Span offsetSpan, VST.Span fullValuesSpan, VST.Span visibleValuesSpan, VST.Span fullAsciiSpan, VST.Span visibleAsciiSpan) {
			if (hexBufferLineFormatter == null)
				throw new ArgumentNullException(nameof(hexBufferLineFormatter));
			if (columnOrder == null)
				throw new ArgumentNullException(nameof(columnOrder));
			if (bufferSpan.IsDefault)
				throw new ArgumentException();
			if (hexBytes.IsDefault)
				throw new ArgumentException();
			if (text == null)
				throw new ArgumentNullException(nameof(text));
			if (valueCells.IsDefault)
				throw new ArgumentNullException(nameof(valueCells));
			if (asciiCells.IsDefault)
				throw new ArgumentNullException(nameof(asciiCells));
			LineProvider = hexBufferLineFormatter;
			LineNumber = lineNumber;
			ColumnOrder = columnOrder;
			BufferSpan = bufferSpan;
			HexBytes = hexBytes;
			Text = text;
			IsOffsetColumnPresent = isOffsetColumnPresent;
			IsValuesColumnPresent = isValuesColumnPresent;
			IsAsciiColumnPresent = isAsciiColumnPresent;
			LogicalOffset = logicalOffset;
			ValueCells = valueCells;
			AsciiCells = asciiCells;
			this.offsetSpan = offsetSpan;
			this.fullValuesSpan = fullValuesSpan;
			this.visibleValuesSpan = visibleValuesSpan;
			this.fullAsciiSpan = fullAsciiSpan;
			this.visibleAsciiSpan = visibleAsciiSpan;
		}
Example #2
0
		public override string GenerateHtmlFragment(NormalizedHexBufferSpanCollection spans, HexBufferLineFormatter bufferLines, string delimiter, CancellationToken cancellationToken) {
			if (spans == null)
				throw new ArgumentNullException(nameof(spans));
			if (bufferLines == null)
				throw new ArgumentNullException(nameof(bufferLines));
			if (delimiter == null)
				throw new ArgumentNullException(nameof(delimiter));
			if (spans.Count != 0 && spans[0].Buffer != bufferLines.Buffer)
				throw new ArgumentException();

			return GenerateHtmlFragmentCore(bufferLines, spans, null, delimiter, cancellationToken);
		}
Example #3
0
		public void Add(HexBufferLineFormatter bufferLines, HexClassifier classifier, NormalizedHexBufferSpanCollection spans, CancellationToken cancellationToken) {
			if (bufferLines == null)
				throw new ArgumentNullException(nameof(bufferLines));
			if (classifier == null)
				throw new ArgumentNullException(nameof(classifier));
			if (spans == null)
				throw new ArgumentNullException(nameof(spans));
			if (spans.Count != 0 && spans[0].Buffer != bufferLines.Buffer)
				throw new ArgumentException();

			var classificationSpans = new List<HexClassificationSpan>();
			foreach (var span in spans) {
				if (spansCount > 0)
					htmlWriter.WriteRaw(delimiter);
				spansCount++;

				var pos = span.Start;
				for (;;) {
					classificationSpans.Clear();
					var line = bufferLines.GetLineFromPosition(pos);
					var text = line.GetText(span);
					var context = new HexClassificationContext(line, line.TextSpan);
					classifier.GetClassificationSpans(classificationSpans, context, cancellationToken);

					int textPos = 0;
					foreach (var tagSpan in classificationSpans) {
						if (textPos < tagSpan.Span.Start) {
							WriteCss(classificationFormatMap.DefaultTextProperties);
							htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, tagSpan.Span.Start - textPos);
						}
						WriteCss(classificationFormatMap.GetTextProperties(tagSpan.ClassificationType));
						htmlWriter.WriteSpan(cssWriter.ToString(), text, tagSpan.Span.Start, tagSpan.Span.Length);
						textPos = tagSpan.Span.End;
					}
					if (textPos < text.Length) {
						WriteCss(classificationFormatMap.DefaultTextProperties);
						htmlWriter.WriteSpan(cssWriter.ToString(), text, textPos, text.Length - textPos);
					}
					htmlWriter.WriteRaw("<br/>");

					pos = line.BufferEnd;
					if (pos >= span.End)
						break;
				}
			}
		}
Example #4
0
		string GenerateHtmlFragmentCore(HexBufferLineFormatter bufferLines, NormalizedHexBufferSpanCollection spans, HexView hexView, string delimiter, CancellationToken cancellationToken) {
			HexClassifier classifier = null;
			try {
				VSTC.IClassificationFormatMap classificationFormatMap;
				if (hexView != null) {
					classifier = viewClassifierAggregatorService.GetClassifier(hexView);
					classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(hexView);
				}
				else {
					classifier = spans.Count == 0 ? null : classifierAggregatorService.GetClassifier(spans[0].Buffer);
					classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(AppearanceCategoryConstants.HexEditor);
				}

				const int tabSize = 4;
				var builder = new HexHtmlBuilder(classificationFormatMap, delimiter, tabSize);
				if (spans.Count != 0)
					builder.Add(bufferLines, classifier, spans, cancellationToken);
				return builder.Create();
			}
			finally {
				classifier.Dispose();
			}
		}
Example #5
0
		void RaiseBufferLinesChanged(HexBufferLineFormatter oldBufferLines) {
			// Always access the property so it's recreated if the backing field is null
			var newBufferLines = BufferLines;
			BufferLinesChanged?.Invoke(this, new BufferLinesChangedEventArgs(oldBufferLines, newBufferLines));
		}
Example #6
0
		static PhysicalLine CreatePhysicalLineNoCache(HexBufferLineFormatter bufferLines, HexFormattedLineSource formattedLineSource, HexBufferPoint bufferPosition) {
			var bufferLine = bufferLines.GetLineFromPosition(bufferPosition);
			var formattedLine = formattedLineSource.FormatLineInVisualBuffer(bufferLine);
			return new PhysicalLine(new[] { formattedLine });
		}
			public bool TryUpdateBufferLines(HexBufferLineFormatter bufferLines) => BufferLines == bufferLines;
			public MouseLeftDownInfo(HexBufferSpan span, Point point, int clicks, HexBufferLineFormatter bufferLines) {
				Span = span;
				Point = point;
				Clicks = clicks;
				BufferLines = bufferLines;
			}
Example #9
0
		void WpfHexView_Closed(object sender, EventArgs e) {
			RemoveAllRectangles();
			latestBufferLines = null;
			wpfHexView.Closed -= WpfHexView_Closed;
			wpfHexView.Options.OptionChanged -= Options_OptionChanged;
			UnhookEnabledEvents();
		}
Example #10
0
		void RecreateRectangles() {
			delayRecreateRectanglesCalled = false;
			if (wpfHexView.IsClosed)
				return;

			RemoveAllRectangles();
			if (!enabled)
				return;

			if (wpfHexView.ViewportHeight == 0)
				return;

			var line = wpfHexView.HexViewLines.FirstVisibleLine;
			var top = wpfHexView.ViewportTop;
			var bottom = wpfHexView.ViewportBottom;
			foreach (var info in GetRectanglePositions(line)) {
				var props = editorFormatMap.GetProperties(GetClassificationTypeName(info.Key));
				var bgBrush = GetBackgroundBrush(props);
				if (bgBrush == null || TWPF.BrushComparer.Equals(bgBrush, Brushes.Transparent))
					continue;
				var lineElem = new RectangleElement(info.Key, info.Value, bgBrush, null);
				bool added = adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, lineElem, null);
				if (added)
					rectangleElements.Add(lineElem);
			}

			latestBufferLines = wpfHexView.BufferLines;
		}
Example #11
0
		void RecreateColumnLines() {
			delayRecreateColumnLinesCalled = false;
			if (wpfHexView.IsClosed)
				return;

			RemoveAllLines();
			if (!enabled)
				return;

			if (wpfHexView.ViewportHeight == 0)
				return;

			var line = wpfHexView.HexViewLines.FirstVisibleLine;
			var top = wpfHexView.ViewportTop;
			var bottom = wpfHexView.ViewportBottom;
			foreach (var info in GetColumnPositions(line.BufferLine)) {
				var lineKind = GetColumnLineKind(info.Key);
				if (lineKind == HexColumnLineKind.None)
					continue;
				var props = editorFormatMap.GetProperties(classificationTypeNames[(int)info.Key]);
				var pen = GetPen(props, lineKind);
				var bounds = line.GetCharacterBounds(info.Value);
				var x = Math.Round(bounds.Left + bounds.Width / 2 - PEN_THICKNESS / 2) + 0.5;
				var lineElem = new LineElement(info.Key, x, top, bottom, pen);
				bool added = adornmentLayer.AddAdornment(VSTE.AdornmentPositioningBehavior.OwnerControlled, (HexBufferSpan?)null, null, lineElem, null);
				if (added)
					lineElements.Add(lineElem);
			}

			latestBufferLines = wpfHexView.BufferLines;
		}
Example #12
0
		static HexCell GetCell(HexBufferLineFormatter bufferLines, HexBufferPoint position) {
			var line = bufferLines.GetLineFromPosition(position);
			var cell = line.ValueCells.GetCell(position);
			if (cell == null && position == line.BufferEnd && position > line.BufferStart)
				cell = line.ValueCells.GetCell(position - 1);
			return cell;
		}