/// <summary> /// 新输入 /// </summary> /// <param name="insertion"></param> /// <returns></returns> public override bool Insert(string insertion) { RegExpMaskManagerState state; MaskManagerStated.StateChangeType changeType = ((insertion.Length == 0) && base.IsSelection) ? MaskManagerStated.StateChangeType.Delete : MaskManagerStated.StateChangeType.Insert; string head = GetCurrentEditText().Substring(0, base.DisplaySelectionStart); string replaced = GetCurrentEditText().Substring(base.DisplaySelectionStart, base.DisplaySelectionLength); string tail = GetCurrentEditText().Substring(base.DisplaySelectionEnd); MaskLogicResult result = _logic.GetReplaceResult(head, replaced, tail, insertion); if (result == null) { return(false); } if (_reverseDfa) { state = new RegExpMaskManagerState(result.EditText, base.DisplaySelectionStart, base.DisplaySelectionStart); } else if ((_isOptimistic && (changeType == MaskManagerStated.StateChangeType.Insert)) && (tail.Length == 0)) { string editText = _logic.OptimisticallyExpand(result.EditText); state = new RegExpMaskManagerState(editText, result.CursorPosition, editText.Length); } else { state = new RegExpMaskManagerState(result.EditText, result.CursorPosition, result.CursorPosition); } return(base.Apply(state, changeType)); }
/// <summary> /// 设置初始文本 /// </summary> /// <param name="initialEditText"></param> public override void SetInitialEditText(string initialEditText) { MaskLogicResult result = _logic.GetReplaceResult(initialEditText ?? string.Empty, string.Empty, string.Empty, string.Empty); if (result != null) { Apply(result.EditText, result.CursorPosition, result.CursorPosition, MaskManagerStated.StateChangeType.Insert); } else { base.SetInitialState(RegExpMaskManagerState.Empty); if (!Insert(initialEditText)) { bool flag = false; foreach (char ch in initialEditText) { if (Insert(ch.ToString())) { flag = true; } } if (!flag) { Insert(string.Empty); } } base.SetInitialState(new RegExpMaskManagerState(CurrentState.EditText, CurrentState.CursorPosition, CurrentState.SelectionAnchor)); } }
bool SpinKeys(bool isUp) { bool flag; int cursorPosition = CurrentState.CursorPosition; if (CurrentState.SelectionAnchor != CurrentState.CursorPosition) { int startIndex = (CurrentState.SelectionAnchor < CurrentState.CursorPosition) ? CurrentState.SelectionAnchor : CurrentState.CursorPosition; int num3 = (CurrentState.SelectionAnchor < CurrentState.CursorPosition) ? CurrentState.CursorPosition : CurrentState.SelectionAnchor; if (((startIndex == 0) && (num3 == CurrentState.EditText.Length)) || (CurrentState.EditText.Substring(startIndex, num3 - startIndex).IndexOf('.') >= 0)) { cursorPosition = CurrentState.EditText.IndexOf('.'); if (cursorPosition < 0) { cursorPosition = CurrentState.EditText.Length; } } else { cursorPosition = num3; } } bool isModuloDecrement = isUp ? CurrentState.IsNegative : !CurrentState.IsNegative; MaskLogicResult result = _logic.GetSpinResult(CurrentState.EditText.Substring(0, cursorPosition), CurrentState.EditText.Substring(cursorPosition), isModuloDecrement, IsSignedMask, out flag); if (result == null) { return(false); } bool isNegative = flag ? !CurrentState.IsNegative : CurrentState.IsNegative; return(base.Apply(new NumericMaskManagerState(result.EditText, result.CursorPosition, result.CursorPosition, isNegative), MaskManagerStated.StateChangeType.Insert)); }
/// <summary> /// /// </summary> /// <param name="insertion"></param> /// <returns></returns> public override bool Insert(string insertion) { if (IsSignedMask && ((insertion == "-") || (insertion == _negativeSignString))) { if (!CurrentState.IsNull) { return(base.Apply(new NumericMaskManagerState(CurrentState.EditText, CurrentState.CursorPosition, CurrentState.SelectionAnchor, !CurrentState.IsNegative), MaskManagerStated.StateChangeType.Insert)); } MaskLogicResult result = _logic.GetEditResult(string.Empty, string.Empty, string.Empty, string.Empty); if (result == null) { return(false); } return(base.Apply(new NumericMaskManagerState(result.EditText, 0, result.EditText.Length, true), MaskManagerStated.StateChangeType.Insert)); } int length = (CurrentState.CursorPosition < CurrentState.SelectionAnchor) ? CurrentState.CursorPosition : CurrentState.SelectionAnchor; int startIndex = (CurrentState.CursorPosition < CurrentState.SelectionAnchor) ? CurrentState.SelectionAnchor : CurrentState.CursorPosition; MaskLogicResult result2 = _logic.GetEditResult(CurrentState.EditText.Substring(0, length), CurrentState.EditText.Substring(length, startIndex - length), CurrentState.EditText.Substring(startIndex), insertion); if (result2 == null) { return(false); } bool isNegative = CurrentState.IsNegative; if (IsSignedMask && ((insertion.IndexOf("-") >= 0) || (insertion.IndexOf(_negativeSignString) >= 0))) { isNegative = !isNegative; } return(base.Apply(new NumericMaskManagerState(result2.EditText, result2.CursorPosition, result2.CursorPosition, isNegative), MaskManagerStated.StateChangeType.Insert)); }
/// <summary> /// /// </summary> /// <param name="result"></param> /// <param name="changeType"></param> /// <returns></returns> protected bool Apply(MaskLogicResult result, MaskManagerStated.StateChangeType changeType) { if (result == null) { return(false); } return(base.Apply(new RegExpMaskManagerState(result.EditText, result.CursorPosition, result.CursorPosition), changeType)); }
/// <summary> /// 删除操作 /// </summary> /// <returns></returns> public override bool Delete() { if (base.IsSelection) { return(Insert(string.Empty)); } MaskLogicResult deleteResult = _logic.GetDeleteResult(GetCurrentEditText().Substring(0, DisplayCursorPosition), GetCurrentEditText().Substring(DisplayCursorPosition)); return(Apply(deleteResult, MaskManagerStated.StateChangeType.Delete)); }
/// <summary> /// /// </summary> public override void ClearAfterSelectAll() { if (_AllowNull) { base.Apply(NumericMaskManagerState.NullInstance, MaskManagerStated.StateChangeType.Delete); } else { MaskLogicResult result = _logic.GetEditResult(string.Empty, CurrentState.EditText, string.Empty, string.Empty); base.Apply(new NumericMaskManagerState(result.EditText, result.CursorPosition, result.CursorPosition, false), MaskManagerStated.StateChangeType.Delete); } }