public Lazy<IBackgroundImageOptionDefinition, IBackgroundImageOptionDefinitionMetadata> GetOptionDefinition(WpfHexView wpfTextView) {
			foreach (var lz in backgroundImageOptionDefinitions) {
				if ((lz.Value as IBackgroundImageOptionDefinition2)?.IsSupported(wpfTextView) == true)
					return lz;
			}
			throw new InvalidOperationException();
		}
#pragma warning restore 0169

		HexViewBackgroundImageService(WpfHexView wpfHexView, IImageSourceService imageSourceService)
			: base(imageSourceService) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			this.wpfHexView = wpfHexView;
			wpfHexView.Closed += WpfHexView_Closed;
		}
		public static void InstallService(WpfHexView wpfHexView, IImageSourceService imageSourceService) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			if (imageSourceService == null)
				throw new ArgumentNullException(nameof(imageSourceService));
			wpfHexView.Properties.GetOrCreateSingletonProperty(typeof(BackgroundImageService), () => new HexViewBackgroundImageService(wpfHexView, imageSourceService));
		}
Beispiel #4
0
		public WpfHexViewHostImpl(WpfHexViewMarginProviderCollectionProvider wpfHexViewMarginProviderCollectionProvider, WpfHexView wpfHexView, HexEditorOperationsFactoryService editorOperationsFactoryService, bool setFocus) {
			if (wpfHexViewMarginProviderCollectionProvider == null)
				throw new ArgumentNullException(nameof(wpfHexViewMarginProviderCollectionProvider));
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			if (editorOperationsFactoryService == null)
				throw new ArgumentNullException(nameof(editorOperationsFactoryService));
			contentControl = new ContentControl();
			this.editorOperationsFactoryService = editorOperationsFactoryService;
			grid = CreateGrid();
			HexView = wpfHexView;
			contentControl.Focusable = false;
			contentControl.Content = grid;
			contentControl.MouseWheel += ContentControl_MouseWheel;

			UpdateBackground();
			HexView.BackgroundBrushChanged += HexView_BackgroundBrushChanged;

			containerMargins = new WpfHexViewMargin[5];
			containerMargins[0] = CreateContainerMargin(wpfHexViewMarginProviderCollectionProvider, PredefinedHexMarginNames.Top, true, 0, 0, 3);
			containerMargins[1] = CreateContainerMargin(wpfHexViewMarginProviderCollectionProvider, PredefinedHexMarginNames.Bottom, true, 2, 0, 2);
			containerMargins[2] = CreateContainerMargin(wpfHexViewMarginProviderCollectionProvider, PredefinedHexMarginNames.BottomRightCorner, true, 2, 2, 1);
			containerMargins[3] = CreateContainerMargin(wpfHexViewMarginProviderCollectionProvider, PredefinedHexMarginNames.Left, false, 1, 0, 1);
			containerMargins[4] = CreateContainerMargin(wpfHexViewMarginProviderCollectionProvider, PredefinedHexMarginNames.Right, false, 1, 2, 1);
			Add(HexView.VisualElement, 1, 1, 1);
			Debug.Assert(!containerMargins.Any(a => a == null));

			if (setFocus) {
				contentControl.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => {
					if (!HexView.IsClosed)
						HexView.VisualElement.Focus();
				}));
			}
		}
Beispiel #5
0
		public static void AddGeometries(WpfHexView hexView, Collection<VSTF.TextBounds> textBounds, bool isLineGeometry, bool clipToViewport, Thickness padding, double minWidth, ref PathGeometry geo, ref bool createOutlinedPath) {
			foreach (var bounds in textBounds) {
				double left = bounds.Left - padding.Left;
				double right = bounds.Right + padding.Right;
				double top, bottom;
				if (isLineGeometry) {
					top = bounds.Top - padding.Top;
					bottom = bounds.Bottom + padding.Bottom;
				}
				else {
					top = bounds.TextTop - padding.Top;
					bottom = bounds.TextBottom + padding.Bottom;
				}
				if (right - left < minWidth)
					right = left + minWidth;
				if (clipToViewport) {
					left = Math.Max(left, hexView.ViewportLeft);
					right = Math.Min(right, hexView.ViewportRight);
				}
				if (right <= left || bottom <= top)
					continue;
				const double MAX_HEIGHT = 1000000;
				const double MAX_WIDTH = 1000000;
				double width = Math.Min(right - left, MAX_WIDTH);
				double height = Math.Min(bottom - top, MAX_HEIGHT);

				if (geo == null)
					geo = new PathGeometry { FillRule = FillRule.Nonzero };
				else
					createOutlinedPath = true;
				geo.AddGeometry(new RectangleGeometry(new Rect(left, top, width, height)));
			}
		}
		public HexContextMenuInitializer(WpfHexView hexView, FrameworkElement ctrl) {
			if (hexView == null)
				throw new ArgumentNullException(nameof(hexView));
			if (ctrl == null)
				throw new ArgumentNullException(nameof(ctrl));
			this.hexView = hexView;
			this.ctrl = ctrl;
		}
		internal string GetSubGroup(WpfHexView hexView) {
			foreach (var lz in tagOptionDefinitionProviders) {
				var subGroup = lz.Value.GetSubGroup(hexView);
				if (subGroup != null)
					return subGroup;
			}
			return null;
		}
Beispiel #8
0
		public OffsetHexMouseProcessor(OffsetCursorProvider offsetCursorProvider, WpfHexView wpfHexView) {
			if (offsetCursorProvider == null)
				throw new ArgumentNullException(nameof(offsetCursorProvider));
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			this.offsetCursorProvider = offsetCursorProvider;
			this.wpfHexView = wpfHexView;
		}
		public HexSpaceReservationManagerImpl(WpfHexView wpfHexView) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			this.wpfHexView = wpfHexView;
			spaceReservationAgents = new List<HexSpaceReservationAgent>();
			Agents = new ReadOnlyCollection<HexSpaceReservationAgent>(spaceReservationAgents);
			wpfHexView.Closed += WpfHexView_Closed;
		}
		public HexViewMouseProcessorCollection(WpfHexView wpfHexView, HexEditorOperationsFactoryService editorOperationsFactoryService, Lazy<HexMouseProcessorProvider, IOrderableTextViewRoleMetadata>[] mouseProcessorProviders) {
			this.wpfHexView = wpfHexView;
			wpfHexViewImpl = wpfHexView as WpfHexViewImpl;
			this.editorOperationsFactoryService = editorOperationsFactoryService;
			this.mouseProcessorProviders = mouseProcessorProviders;
			allowEventDelegate = AllowMouseEvent;
			wpfHexView.Closed += WpfHexView_Closed;
			Reinitialize();
		}
		public HexAdornmentLayerImpl(WpfHexView hexView, HexLayerKind layerKind, MetadataAndOrder<IAdornmentLayersMetadata> info) {
			if (hexView == null)
				throw new ArgumentNullException(nameof(hexView));
			canvas = new Canvas();
			HexView = hexView;
			this.layerKind = layerKind;
			Info = info;
			adornmentLayerElements = new List<HexAdornmentLayerElementImpl>();
		}
Beispiel #12
0
		public static Size TransformToDevice(WpfHexView wpfHexView, Size size) {
			var zoomMultiplier = wpfHexView.ZoomLevel == 0 ? 1 : wpfHexView.ZoomLevel / 100;
			var source = PresentationSource.FromVisual(wpfHexView.VisualElement);
			var transformToDevice = source?.CompositionTarget.TransformToDevice ?? Matrix.Identity;
			var wpfRect = transformToDevice.Transform(new Point(size.Width, size.Height));
			var width = wpfRect.X * zoomMultiplier;
			var height = wpfRect.Y * zoomMultiplier;
			return new Size(width, height);
		}
Beispiel #13
0
		public static Rect TransformFromDevice(WpfHexView wpfHexView, Rect rect) {
			var zoomMultiplier = wpfHexView.ZoomLevel == 0 ? 1 : 100 / wpfHexView.ZoomLevel;
			var source = PresentationSource.FromVisual(wpfHexView.VisualElement);
			var transformFromDevice = source?.CompositionTarget.TransformFromDevice ?? Matrix.Identity;
			var viewPoint = wpfHexView.VisualElement.PointToScreen(new Point(0, 0));
			var fixedRect = new Rect((rect.Left - viewPoint.X) * zoomMultiplier, (rect.Top - viewPoint.Y) * zoomMultiplier, rect.Width * zoomMultiplier, rect.Height * zoomMultiplier);
			var topLeft = transformFromDevice.Transform(fixedRect.TopLeft);
			var bottomRight = transformFromDevice.Transform(fixedRect.BottomRight);
			return new Rect(topLeft, bottomRight);
		}
		public void InitializeOptions(WpfHexView hexView) {
			foreach (var option in Options) {
				try {
					hexView.Options.SetOptionValue(option.OptionId, option.Value);
				}
				catch (ArgumentException) {
					// Invalid option value
				}
			}
		}
		public HexSpaceReservationStackImpl(WpfHexView wpfHexView, string[] spaceReservationManagerNames) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			if (spaceReservationManagerNames == null)
				throw new ArgumentNullException(nameof(spaceReservationManagerNames));
			this.wpfHexView = wpfHexView;
			this.spaceReservationManagerNames = spaceReservationManagerNames;
			spaceReservationManagers = new HexSpaceReservationManagerImpl[spaceReservationManagerNames.Length];
			wpfHexView.Closed += WpfHexView_Closed;
		}
		public override HexLineTransformProvider Create(WpfHexView hexView, bool removeExtraTextLineVerticalPixels) {
			var list = new List<HexLineTransformSource>();
			foreach (var lz in lineTransformSourceProviders) {
				if (!hexView.Roles.ContainsAny(lz.Metadata.TextViewRoles))
					continue;
				var source = lz.Value.Create(hexView);
				if (source != null)
					list.Add(source);
			}
			return new HexLineTransformProviderImpl(list.ToArray(), removeExtraTextLineVerticalPixels);
		}
		public HexAdornmentLayerCollection(WpfHexView wpfHexView, HexLayerKind layerKind) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			this.wpfHexView = wpfHexView;
			this.layerKind = layerKind;
			adornmentLayers = new List<HexAdornmentLayerImpl>();
			if (layerKind != HexLayerKind.Normal)
				ClipToBounds = true;
			wpfHexView.Closed += WpfHexView_Closed;
			wpfHexView.LayoutChanged += WpfHexView_LayoutChanged;
		}
		public CurrentLineHighlighter(WpfHexView wpfHexView, VSTC.IEditorFormatMap editorFormatMap) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			if (editorFormatMap == null)
				throw new ArgumentNullException(nameof(editorFormatMap));
			this.wpfHexView = wpfHexView;
			this.editorFormatMap = editorFormatMap;
			currentLineHighlighterElement = new CurrentLineHighlighterElement();
			wpfHexView.Closed += WpfHexView_Closed;
			wpfHexView.Options.OptionChanged += Options_OptionChanged;
			UpdateEnableState();
		}
		static void SelectAndMoveCaret(WpfHexView hexView, HexSpan span) {
			if (!hexView.VisualElement.IsLoaded) {
				RoutedEventHandler loaded = null;
				loaded = (s, e) => {
					hexView.VisualElement.Loaded -= loaded;
					InitializeHexView(hexView, span);
				};
				hexView.VisualElement.Loaded += loaded;
			}
			else
				InitializeHexView(hexView, span);
		}
			public HexViewState(WpfHexView hexView, Lazy<HexIntellisenseControllerProvider>[] intellisenseControllerProviders) {
				this.hexView = hexView;
				var list = new List<HexIntellisenseController>(intellisenseControllerProviders.Length);
				foreach (var provider in intellisenseControllerProviders) {
					var controller = provider.Value.TryCreateIntellisenseController(hexView);
					if (controller != null)
						list.Add(controller);
				}
				intellisenseControllers = list.ToArray();
				if (intellisenseControllers.Length != 0)
					hexView.Closed += HexView_Closed;
			}
Beispiel #21
0
		public static void SetScaleTransform(WpfHexView wpfHexView, FrameworkElement popupElement) {
			if (wpfHexView == null)
				return;
			var metroWindow = Window.GetWindow(wpfHexView.VisualElement) as MetroWindow;
			if (metroWindow == null)
				return;
			metroWindow.SetScaleTransform(popupElement, wpfHexView.ZoomLevel / 100);

			var maxSize = GetMaxSize(wpfHexView);
			popupElement.MaxWidth = maxSize.Width;
			popupElement.MaxHeight = maxSize.Height;
		}
Beispiel #22
0
		public HexSelectionImpl(WpfHexView hexView, HexAdornmentLayer selectionLayer, VSTC.IEditorFormatMap editorFormatMap) {
			if (hexView == null)
				throw new ArgumentNullException(nameof(hexView));
			if (selectionLayer == null)
				throw new ArgumentNullException(nameof(selectionLayer));
			if (editorFormatMap == null)
				throw new ArgumentNullException(nameof(editorFormatMap));
			HexView = hexView;
			HexView.GotAggregateFocus += HexView_GotAggregateFocus;
			HexView.LostAggregateFocus += HexView_LostAggregateFocus;
			hexSelectionLayer = new HexSelectionLayer(this, selectionLayer, editorFormatMap);
			ActivationTracksFocus = true;
		}
		public WpfHexViewLineCollectionImpl(WpfHexView hexView, IList<WpfHexViewLine> lines) {
			if (hexView == null)
				throw new ArgumentNullException(nameof(hexView));
			if (lines == null)
				throw new ArgumentNullException(nameof(lines));
			this.hexView = hexView;
			this.lines = new ReadOnlyCollection<WpfHexViewLine>(lines);
			isValid = true;
			if (lines.Count == 0)
				formattedSpan = new HexBufferSpan(hexView.Buffer, new HexSpan(HexPosition.Zero, 0));
			else
				formattedSpan = new HexBufferSpan(lines[0].BufferStart, lines[lines.Count - 1].BufferEnd);
			Debug.Assert(this.lines.Count > 0);
		}
Beispiel #24
0
		public HexQuickInfoPresenter(HexQuickInfoSession session)
			: base(session) {
			wpfHexView = session.HexView as WpfHexView;
			Debug.Assert(wpfHexView != null);
			popup = new Popup {
				PlacementTarget = wpfHexView?.VisualElement,
				Placement = PlacementMode.Relative,
				Visibility = Visibility.Collapsed,
				IsOpen = false,
				AllowsTransparency = true,
				UseLayoutRounding = true,
				SnapsToDevicePixels = true,
			};
		}
		public HexIntellisenseSessionStackImpl(WpfHexView wpfHexView) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			this.wpfHexView = wpfHexView;
			sessions = new ObservableCollection<HexIntellisenseSession>();
			commandTargetFilter = new CommandTargetFilter(this);
			sessionStates = new List<SessionState>();
			clearOpacityTimer = new DispatcherTimer(DispatcherPriority.Background, wpfHexView.VisualElement.Dispatcher);
			clearOpacityTimer.Interval = TimeSpan.FromMilliseconds(clearOpacityIntervalMilliSecs);
			clearOpacityTimer.Tick += ClearOpacityTimer_Tick;
			Sessions = new ReadOnlyObservableCollection<HexIntellisenseSession>(sessions);
			wpfHexView.Closed += WpfHexView_Closed;
			wpfHexView.VisualElement.KeyDown += VisualElement_KeyDown;
			wpfHexView.VisualElement.KeyUp += VisualElement_KeyUp;
		}
Beispiel #26
0
		public static HexMouseLocation TryCreateTextOnly(WpfHexView wpfHexView, MouseEventArgs e) {
			var point = GetTextPoint(wpfHexView, e);
			var line = wpfHexView.HexViewLines.GetHexViewLineContainingYCoordinate(point.Y);
			if (line == null)
				return null;
			if (!(line.TextTop <= point.Y && point.Y < line.TextBottom))
				return null;
			if (!(line.TextLeft <= point.X && point.X < line.TextRight))
				return null;
			var position = line.GetLinePositionFromXCoordinate(point.X, true);
			if (position == null)
				return null;

			return new HexMouseLocation(line, position.Value, point);
		}
		public HexKeyProcessorCollection(WpfHexView wpfHexView, Lazy<HexKeyProcessorProvider, IOrderableTextViewRoleMetadata>[] keyProcessorProviders) {
			this.wpfHexView = wpfHexView;
			this.keyProcessorProviders = keyProcessorProviders;
			keyProcessors = Array.Empty<HexKeyProcessor>();
			wpfHexView.Closed += WpfHexView_Closed;
			wpfHexView.VisualElement.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(VisualElement_KeyDown), true);
			wpfHexView.VisualElement.AddHandler(UIElement.KeyUpEvent, new KeyEventHandler(VisualElement_KeyUp), true);
			wpfHexView.VisualElement.AddHandler(UIElement.PreviewKeyDownEvent, new KeyEventHandler(VisualElement_PreviewKeyDown), true);
			wpfHexView.VisualElement.AddHandler(UIElement.PreviewKeyUpEvent, new KeyEventHandler(VisualElement_PreviewKeyUp), true);
			wpfHexView.VisualElement.AddHandler(UIElement.TextInputEvent, new TextCompositionEventHandler(VisualElement_TextInput), true);
			wpfHexView.VisualElement.AddHandler(UIElement.PreviewTextInputEvent, new TextCompositionEventHandler(VisualElement_PreviewTextInput), true);
			wpfHexView.VisualElement.AddHandler(TextCompositionManager.TextInputStartEvent, new TextCompositionEventHandler(VisualElement_TextInputStart), true);
			wpfHexView.VisualElement.AddHandler(TextCompositionManager.PreviewTextInputStartEvent, new TextCompositionEventHandler(VisualElement_PreviewTextInputStart), true);
			wpfHexView.VisualElement.AddHandler(TextCompositionManager.TextInputUpdateEvent, new TextCompositionEventHandler(VisualElement_TextInputUpdate), true);
			wpfHexView.VisualElement.AddHandler(TextCompositionManager.PreviewTextInputUpdateEvent, new TextCompositionEventHandler(VisualElement_PreviewTextInputUpdate), true);
			Reinitialize();
		}
Beispiel #28
0
		public static HexMouseLocation Create(WpfHexView wpfHexView, MouseEventArgs e, bool insertionPosition) {
			HexViewLine hexViewLine;
			int position;

			var point = GetTextPoint(wpfHexView, e);
			var line = wpfHexView.HexViewLines.GetHexViewLineContainingYCoordinate(point.Y);
			if (line != null)
				hexViewLine = line;
			else if (point.Y <= wpfHexView.ViewportTop)
				hexViewLine = wpfHexView.HexViewLines.FirstVisibleLine;
			else
				hexViewLine = wpfHexView.HexViewLines.LastVisibleLine;
			if (insertionPosition)
				position = hexViewLine.GetInsertionLinePositionFromXCoordinate(point.X);
			else
				position = hexViewLine.GetVirtualLinePositionFromXCoordinate(point.X);

			return new HexMouseLocation(hexViewLine, position, point);
		}
		public HexPopupSpaceReservationAgent(HexSpaceReservationManager spaceReservationManager, WpfHexView wpfHexView, HexLineSpan lineSpan, VSTA.PopupStyles style, UIElement content) {
			if (spaceReservationManager == null)
				throw new ArgumentNullException(nameof(spaceReservationManager));
			if (lineSpan.IsDefault)
				throw new ArgumentException();
			if (content == null)
				throw new ArgumentNullException(nameof(content));
			if ((style & (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent)) == (VSTA.PopupStyles.DismissOnMouseLeaveText | VSTA.PopupStyles.DismissOnMouseLeaveTextOrContent))
				throw new ArgumentOutOfRangeException(nameof(style));
			this.spaceReservationManager = spaceReservationManager;
			this.wpfHexView = wpfHexView;
			this.lineSpan = lineSpan;
			this.style = style;
			this.content = content;
			popup = new Popup {
				PlacementTarget = wpfHexView.VisualElement,
				Placement = PlacementMode.Relative,
				Visibility = Visibility.Collapsed,
				IsOpen = false,
				AllowsTransparency = true,
				UseLayoutRounding = true,
				SnapsToDevicePixels = true,
			};
		}
Beispiel #30
0
		public HexMarkerService(WpfHexView wpfHexView, HexTagAggregator<HexMarkerTag> tagAggregator, VSTC.IEditorFormatMap editorFormatMap, IThemeService themeService) {
			if (wpfHexView == null)
				throw new ArgumentNullException(nameof(wpfHexView));
			if (tagAggregator == null)
				throw new ArgumentNullException(nameof(tagAggregator));
			if (editorFormatMap == null)
				throw new ArgumentNullException(nameof(editorFormatMap));
			if (themeService == null)
				throw new ArgumentNullException(nameof(themeService));
			this.wpfHexView = wpfHexView;
			this.tagAggregator = tagAggregator;
			this.editorFormatMap = editorFormatMap;
			this.themeService = themeService;
			textMarkerAdornmentLayer = wpfHexView.GetAdornmentLayer(PredefinedHexAdornmentLayers.TextMarker);
			negativeTextMarkerAdornmentLayer = wpfHexView.GetAdornmentLayer(PredefinedHexAdornmentLayers.NegativeTextMarker);
			markerElements = new List<MarkerElement>();
			useReducedOpacityForHighContrast = wpfHexView.Options.GetOptionValue(DefaultWpfHexViewOptions.UseReducedOpacityForHighContrastOptionId);
			onRemovedDelegate = OnRemoved;
			wpfHexView.Closed += WpfHexView_Closed;
			wpfHexView.LayoutChanged += WpfHexView_LayoutChanged;
			wpfHexView.Options.OptionChanged += Options_OptionChanged;
			tagAggregator.BatchedTagsChanged += TagAggregator_BatchedTagsChanged;
			editorFormatMap.FormatMappingChanged += EditorFormatMap_FormatMappingChanged;
		}
 /// <summary>
 /// Creates a new <see cref="WpfHexViewHost"/>
 /// </summary>
 /// <param name="wpfHexView">Hex view</param>
 /// <param name="setFocus">true to set focus</param>
 /// <returns></returns>
 public abstract WpfHexViewHost CreateHost(WpfHexView wpfHexView, bool setFocus);
Beispiel #32
0
 /// <summary>
 /// Creates a <see cref="HexCursorProvider"/> instance or returns null
 /// </summary>
 /// <param name="wpfHexView">Hex view</param>
 /// <returns></returns>
 public abstract HexCursorProvider Create(WpfHexView wpfHexView);