Example #1
0
 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;
 }
Example #2
0
		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;
		}
Example #3
0
		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;
		}
Example #4
0
		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);
		}
Example #5
0
		public void SelectAll() {
			Selection = new HexSelection(StartOffset, EndOffset);
			SetCaretPosition(MoveToEndOfSelection(CaretPosition));
		}
Example #6
0
		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);
		}
Example #7
0
		void UnselectText(Action action, bool forceUnselect = true) {
			var oldPos = CaretPosition;
			action();
			if (forceUnselect || oldPos != CaretPosition)
				Selection = null;
		}
Example #8
0
		void UpdateSelection() {
			// The prop will verify the selection and update it if necessary
			Selection = Selection;
		}