void UpdateCaptureMouseSelection(ulong? startOffset, HexBoxPosition position, HexPositionUI uiPos) { SetCaretPosition(position); if (startOffset == null) return; if (Selection != null || uiPos != mouseCaptureStartPosUI) Selection = new HexSelection(startOffset.Value, position.Offset); }
ulong GetLineOffset(HexPositionUI docPos) { ulong bpl = (ulong)(visibleBytesPerLine == 0 ? 1 : visibleBytesPerLine); return NumberUtils.AddUInt64(StartOffset, NumberUtils.MulUInt64(docPos.Y, bpl)); }
HexBoxPosition? GetPositionFrom(HexPositionUI docPos, double xpos) { ulong lineOffset = GetLineOffset(docPos); int hexByteCharIndex; ulong? hexByteIndex = TryGetHexByteLineIndex(docPos.X, xpos, out hexByteCharIndex); if (hexByteIndex != null) return HexBoxPosition.CreateByte(NumberUtils.AddUInt64(lineOffset, hexByteIndex.Value), hexByteCharIndex); ulong? asciiIndex = TryGetAsciiLineIndex(docPos.X); if (asciiIndex != null) return HexBoxPosition.CreateAscii(NumberUtils.AddUInt64(lineOffset, asciiIndex.Value)); return null; }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { var pos = GetPositionFrom(e); if (pos != null) { if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0) SelectText(() => SetCaretPosition(pos.Value)); else UnselectText(() => SetCaretPosition(pos.Value)); if (CaptureMouse()) { mouseCaptureActive = true; mouseCaptureStartPos = Selection == null ? pos.Value.Offset : Selection.Value.From; mouseCaptureStartPosUI = GetDocumentPositionFromMousePosition(e.GetPosition(this)); } Focus(); e.Handled = true; return; } base.OnMouseLeftButtonDown(e); }