Esempio n. 1
0
		public HexBufferLineImpl(HexBufferLineProvider hexBufferLineProvider, 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 (hexBufferLineProvider == null)
				throw new ArgumentNullException(nameof(hexBufferLineProvider));
			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 = hexBufferLineProvider;
			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;
		}
		public override string GenerateHtmlFragment(NormalizedHexBufferSpanCollection spans, HexBufferLineProvider 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);
		}
			public LayoutHelper(HexBufferLineProvider bufferLines, HexLineTransformProvider lineTransformProvider, double newViewportTop, HashSet<HexViewLine> oldVisibleLines, List<PhysicalLine> oldLines, HexFormattedLineSource formattedLineSource) {
				this.bufferLines = bufferLines;
				this.lineTransformProvider = lineTransformProvider;
				requestedViewportTop = newViewportTop;
				this.oldLines = oldLines;
				this.formattedLineSource = formattedLineSource;
				toPhysicalLine = new Dictionary<HexFormattedLine, PhysicalLine>();
				this.oldVisibleLines = oldVisibleLines;

				foreach (var physLine in oldLines) {
					foreach (var line in physLine.Lines)
						toPhysicalLine[line] = physLine;
				}
			}
Esempio n. 4
0
		public void Add(HexBufferLineProvider 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;
				}
			}
		}
		string GenerateHtmlFragmentCore(HexBufferLineProvider 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();
			}
		}
Esempio n. 6
0
		void WpfHexView_Closed(object sender, EventArgs e) {
			RemoveAllLines();
			latestBufferLines = null;
			wpfHexView.Closed -= WpfHexView_Closed;
			wpfHexView.Options.OptionChanged -= Options_OptionChanged;
			UnhookEnabledEvents();
		}
Esempio n. 7
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;
		}
		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;
		}
Esempio n. 9
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="oldBufferLines">Old instance</param>
		/// <param name="newBufferLines">New instance</param>
		public BufferLinesChangedEventArgs(HexBufferLineProvider oldBufferLines, HexBufferLineProvider newBufferLines) {
			if (newBufferLines == null)
				throw new ArgumentNullException(nameof(newBufferLines));
			OldBufferLines = oldBufferLines;
			NewBufferLines = newBufferLines;
		}
Esempio n. 10
0
		void RaiseBufferLinesChanged(HexBufferLineProvider 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));
		}
Esempio n. 11
0
		static PhysicalLine CreatePhysicalLineNoCache(HexBufferLineProvider bufferLines, HexFormattedLineSource formattedLineSource, HexBufferPoint bufferPosition) {
			var bufferLine = bufferLines.GetLineFromPosition(bufferPosition);
			var formattedLine = formattedLineSource.FormatLineInVisualBuffer(bufferLine);
			return new PhysicalLine(new[] { formattedLine });
		}
Esempio n. 12
0
		static HexCell GetCell(HexBufferLineProvider 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;
		}