Пример #1
0
            /// <summary>
            /// Initializes states for formatting.
            /// </summary>
            /// <param name="lastCaretPosition">The last caret position before the formatting.</param>
            /// <param name="focusState">The critical state of the TextBox's focus.</param>
            /// <param name="caretPosition"></param>
            /// <param name="unformattedValue"></param>
            /// <param name="jumpCaretToEndOfInteger"></param>
            /// <returns></returns>
            internal ProcessingState GetProcessingStates(
                Int32 lastCaretPosition,
                FocusState focusState,
                Int32 caretPosition,
                String unformattedValue,
                Boolean jumpCaretToEndOfInteger
                )
            {
                var state = new ProcessingState(unformattedValue, jumpCaretToEndOfInteger)
                {
                    Controller        = this,
                    Formatting        = { CaretPosition = caretPosition },
                    LastCaretPosition = lastCaretPosition,
                };

                SetFormattingType(state);
                SetNeedHighlightInput(state);

                SetPreviousStates(state);

                if (state.FormattingType == FormattingAfter.OneSymbolDeleted)
                {
                    state.OneSymbolDeletionType = state.Formatting.CaretPosition < lastCaretPosition
                                                ? DeletionDirection.BackspaceButton
                                                : DeletionDirection.DeleteButton;
                }

                state.GroupSeparatorDeleted = GetStateGroupSeparatorDeleted(state);

                SetPreservePositionForGroupSeparator(state);
                SetPreservePositionForDeletionOfDigitBeforeGroupSeparator(state);

                return(state);
            }
Пример #2
0
            /// <summary>
            /// Defines the formatting type <see cref="FormattingAfter"/>.
            /// </summary>
            /// <param name="state"> </param>
            /// <returns>The value of the  <see cref="FormattingAfter"/></returns>
            private void SetFormattingType(ProcessingState state)
            {
                FormattingAfter formattingAfter;

                if (_textBeforeChangingNotNull.IsNullOrEmpty() &&
                    state.UnformattedValue.IsNullOrEmpty())
                {
                    formattingAfter = FormattingAfter.EmptyValueBeforeAndNow;
                }
                else if (_textBeforeChangingNotNull.IsNotNullOrEmpty() &&
                         state.UnformattedValue.IsNullOrEmpty())
                {
                    formattingAfter = FormattingAfter.EmptyValueBecome;
                }
                else if (state.UnformattedValue == _textBeforeChangingNotNull)
                {
                    formattingAfter = FormattingAfter.ResettingTheSame;
                }
                else if (Math.Abs(state.UnformattedValue.Length - _textBeforeChangingNotNull.Length) != 1)
                {
                    formattingAfter = FormattingAfter.GroupPastingOrDeletion;
                }
                else
                {
                    var subtraction = state.UnformattedValue.Length - _textBeforeChangingNotNull.Length;
                    formattingAfter = 0 < subtraction
                                                ? FormattingAfter.OneSymbolAdded
                                                : FormattingAfter.OneSymbolDeleted;
                }

                state.FormattingType = formattingAfter;

                NumberToMoneyConverter.WriteLogAction(() => String.Format("  !! FormattingType = {0}", formattingAfter));
            }
Пример #3
0
            /// <summary>
            /// Sets the previous number states.
            /// </summary>
            /// <param name="state"></param>
            private void SetPreviousStates(ProcessingState state)
            {
                if (_textBeforeChangingNotNull.IsNullOrEmpty())
                {
                    return;
                }

                var number = _textBeforeChangingNotNull.Split(DecimalSeparator);

                state.IntegerPrevious = number.First();

                state.PartialPrevious = PartialDisabled ? String.Empty : number.Last();
            }
Пример #4
0
            /// <summary>
            /// <see cref="ProcessingState.PreservePositionForDeletionOfDigitBeforeGroupSeparator"/>.
            /// </summary>
            /// <param name="state"></param>
            private void SetPreservePositionForDeletionOfDigitBeforeGroupSeparator(ProcessingState state)
            {
                if (state.OneSymbolDeletionType != DeletionDirection.DeleteButton)
                {
                    return;
                }
                if (_groupSeparatorDynamic == Char.MinValue)
                {
                    // The Group Separator don't set.
                    return;
                }

                var charAfterCaret    = state.UnformattedValue.ElementAtOrDefault(state.Formatting.CaretPosition);
                var notGroupSeparator = charAfterCaret != _groupSeparatorDynamic;

                if (notGroupSeparator)
                {
                    return;
                }

                state.PreservePositionForDeletionOfDigitBeforeGroupSeparator = true;
            }
Пример #5
0
            /// <summary>
            /// <see cref="ProcessingState.PreservePositionForGroupSeparatorOnFocus"/>.
            /// </summary>
            /// <param name="state"></param>
            private void SetPreservePositionForGroupSeparator(ProcessingState state)
            {
                if (state.FormattingType != FormattingAfter.ResettingTheSame)
                {
                    return;
                }
                if (_groupSeparatorDynamic == Char.MinValue)
                {
                    // The Group Separator don't set.
                    return;
                }

                var charAfterCaret    = state.UnformattedValue.ElementAtOrDefault(state.Formatting.CaretPosition);
                var notGroupSeparator = charAfterCaret != _groupSeparatorDynamic;

                if (notGroupSeparator)
                {
                    return;
                }

                state.PreservePositionForGroupSeparatorOnFocus = true;
            }
Пример #6
0
            private Boolean?GetStateGroupSeparatorDeleted(ProcessingState state)
            {
                if (state.FormattingType != FormattingAfter.OneSymbolDeleted)
                {
                    return(null);
                }

                if (_groupSeparatorDynamic.IsDefault())
                {
                    return(null);
                }

                for (var i = 0; i < state.UnformattedValue.Length; i++)
                {
                    if (state.UnformattedValue[i] == _textBeforeChangingNotNull[i])
                    {
                        continue;
                    }

                    return(_textBeforeChangingNotNull[i] == _groupSeparatorDynamic);
                }

                return(false);
            }
Пример #7
0
 /// <summary>
 /// Sets state that required fire a custom hilighting of an input.
 /// </summary>
 /// <param name="state"></param>
 private void SetNeedHighlightInput(ProcessingState state)
 {
     // it3xl.com: It's a feature for the future.
 }