public HexBoxState(HexBoxState other) { this.TopOffset = other.TopOffset; this.Column = other.Column; this.StartOffset = other.StartOffset; this.EndOffset = other.EndOffset; this.CaretPosition = other.CaretPosition; this.Selection = other.Selection; }
public bool HandleTextInput(string text) { if (Document == null) return false; bool unselect = false; switch (CaretPosition.Kind) { case HexBoxPositionKind.HexByte: foreach (var c in text) { if (c == ' ') MoveCaretRight(); else if (HandleHexByteInput(c)) unselect = true; } break; case HexBoxPositionKind.Ascii: foreach (var c in text) { if (HandleHexAsciiInput(c)) unselect = true; } break; default: throw new InvalidOperationException(); } if (unselect) Selection = null; return true; }
void FillBytes(byte b) { if (Selection == null) { FillBytes(CaretPosition.Offset, CaretPosition.Offset, b); SetCaretPosition(new HexBoxPosition(NumberUtils.AddUInt64(CaretPosition.Offset, 1), CaretPosition.Kind, 0)); } else FillBytes(Selection.Value.StartOffset, Selection.Value.EndOffset, b); Selection = null; }
public void Paste(byte[] data) { if (!CanPaste(data)) return; ulong offs = CaretPosition.Offset; var ctx = NotifyBeforeWrite(HexWriteType.Paste, offs, data.Length); Document.Write(offs, data, 0, data.Length); SetCaretPosition(new HexBoxPosition(NumberUtils.AddUInt64(offs, (ulong)data.Length), CaretPosition.Kind, 0)); Selection = null; BringCaretIntoView(); NotifyAfterWrite(HexWriteType.Paste, offs, data.Length, ctx); }
public void SelectAll() { Selection = new HexSelection(StartOffset, EndOffset); SetCaretPosition(MoveToEndOfSelection(CaretPosition)); }
void SelectText(Action action) { var pos = CaretPosition; var oldSel = Selection; action(); Debug.Assert(oldSel == Selection); if (CaretPosition == pos) return; if (Selection == null) Selection = new HexSelection(pos.Offset, CaretPosition.Offset); else Selection = new HexSelection(Selection.Value.From, CaretPosition.Offset); }
void UnselectText(Action action, bool forceUnselect = true) { var oldPos = CaretPosition; action(); if (forceUnselect || oldPos != CaretPosition) Selection = null; }
void UpdateSelection() { // The prop will verify the selection and update it if necessary Selection = Selection; }