public void Clear(out MaskedTextResultHint resultHint)
    {
      Contract.Ensures(((System.ComponentModel.MaskedTextResultHint)(2)) <= Contract.ValueAtReturn(out resultHint));
      Contract.Ensures(Contract.ValueAtReturn(out resultHint) <= ((System.ComponentModel.MaskedTextResultHint)(4)));

      resultHint = default(MaskedTextResultHint);
    }
    public bool Add(string input, out int testPosition, out MaskedTextResultHint resultHint)
    {
      Contract.Ensures(((System.ComponentModel.MaskedTextResultHint)(-54)) <= Contract.ValueAtReturn(out resultHint));

      testPosition = default(int);
      resultHint = default(MaskedTextResultHint);

      return default(bool);
    }
示例#3
0
        /// <devdoc>
        ///     Attempts to insert the characters in the specified string in at the specified position in the test string,
        ///     shifting characters at upper positions (if any) to make room for the input.
        ///     It performs the insertion if the testOnly parameter is false and the test passes.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        private bool InsertAtInt(string input, int position, out int testPosition, out MaskedTextResultHint resultHint, bool testOnly)
        {
            Debug.Assert(input != null && position >= 0 && position < this.testString.Length, "input param out of range.");

            if (input.Length == 0) // nothing to insert.
            {
                testPosition = position;
                resultHint   = MaskedTextResultHint.NoEffect;
                return true;
            }

            // Test input string first.  testPosition will containt the position of the last inserting character from the input.
            if (!TestString(input, position, out testPosition, out resultHint))
            {
                return false;
            }

            // Now check if we need to open room for the input characters (shift characters right) and if so test the shifting characters.

            int  srcPos          = FindEditPositionFrom(position, forward);               // source position.
            bool shiftNeeded     = FindAssignedEditPositionInRange(srcPos, testPosition, forward) != invalidIndex;
            int  lastAssignedPos = this.LastAssignedPosition;

            if( shiftNeeded && (testPosition == this.testString.Length - 1)) // no room for shifting.
            {
                resultHint   = MaskedTextResultHint.UnavailableEditPosition;
                testPosition = this.testString.Length;
                return false;
            }
            
            int dstPos = FindEditPositionFrom(testPosition + 1, forward);  // destination position.

            if (shiftNeeded)
            {
                // Temp hint used not to overwrite the primary operation result hint (from TestString).
                MaskedTextResultHint tempHint = MaskedTextResultHint.Unknown;

                // Test shifting characters.
                while (true)
                {
                    if (dstPos == invalidIndex)
                    {
                        resultHint   = MaskedTextResultHint.UnavailableEditPosition;
                        testPosition = this.testString.Length;
                        return false;
                    }

                    CharDescriptor chDex = this.stringDescriptor[srcPos];

                    if (chDex.IsAssigned) // only test assigned positions.
                    {
                        if (!TestChar(this.testString[srcPos], dstPos, out tempHint))
                        {
                            resultHint   = tempHint;
                            testPosition = dstPos;
                            return false;
                        }
                    }

                    if (srcPos == lastAssignedPos) // all shifting positions tested?
                    {
                        break;
                    }

                    srcPos = FindEditPositionFrom(srcPos + 1, forward);
                    dstPos = FindEditPositionFrom(dstPos + 1, forward);
                }

                if (tempHint > resultHint)
                {
                    resultHint = tempHint;
                }
            }

            if (testOnly)
            {
                return true; // test done!
            }

            // Tests passed so we can go ahead and shift the existing characters (if needed) and insert the new ones.

            if (shiftNeeded)
            {
                while (srcPos >= position)
                {
                    CharDescriptor chDex = this.stringDescriptor[srcPos];

                    if (chDex.IsAssigned)
                    {
                        SetChar(this.testString[srcPos], dstPos);
                    }
                    else
                    {
                        ResetChar(dstPos);
                    }

                    dstPos = FindEditPositionFrom(dstPos - 1, backward);
                    srcPos = FindEditPositionFrom(srcPos - 1, backward); 
                }
            }

            // Finally set the input characters.
            SetString(input, position);

            return true;
        }
 /// <devdoc>
 ///     Insert or replaces the specified character into the control's text and updates the caret position.  
 ///     If overwrite is true, it replaces the character at the selection start position.
 /// </devdoc>
 private bool PlaceChar(char ch, int startPosition, int length, bool overwrite,
     out MaskedTextResultHint hint)
 {
     return PlaceChar(this.maskedTextProvider, ch, startPosition, length, overwrite, out hint );
 }
		void PostprocessKeyboardInput (bool result, int newPosition, int testPosition, MaskedTextResultHint resultHint)
		{
			if (!result)
				OnMaskInputRejected (new MaskInputRejectedEventArgs (testPosition, resultHint));
			else {
				if (newPosition != MaskedTextProvider.InvalidIndex)
					SelectionStart = newPosition;
				else
					SelectionStart = provider.Length;

				UpdateVisibleText ();
			}
		}
    public bool Replace(string input, int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
    {
      Contract.Ensures(((System.ComponentModel.MaskedTextResultHint)(-55)) <= Contract.ValueAtReturn(out resultHint));
      Contract.Ensures(Contract.ValueAtReturn(out resultHint) <= ((System.ComponentModel.MaskedTextResultHint)(4)));

      testPosition = default(int);
      resultHint = default(MaskedTextResultHint);

      return default(bool);
    }
    public bool InsertAt(char input, int position, out int testPosition, out MaskedTextResultHint resultHint)
    {
      testPosition = default(int);
      resultHint = default(MaskedTextResultHint);

      return default(bool);
    }
示例#8
0
        /// <devdoc>
        ///     Resets the state of the test string edit chars. (Remove all characters from the virtual string).
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        /// </devdoc>
        public void Clear( out MaskedTextResultHint resultHint )
        {
            if (this.assignedCharCount == 0)
            {
                resultHint = MaskedTextResultHint.NoEffect;
                return;
            }

            resultHint = MaskedTextResultHint.Success;

            for( int position = 0; position < this.testString.Length; position++ )
            {
                ResetChar( position );
            }
        }
示例#9
0
        /// <devdoc>
        ///     Replaces the characters in the specified range with the characters in the input string and shifts 
        ///     characters appropriately (removing or inserting characters according to whether the input string is
        ///     shorter or larger than the specified range.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Replace(string input, int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (endPosition >= this.testString.Length)
            {
                testPosition = endPosition;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("endPosition");
            }

            if (startPosition < 0 || startPosition > endPosition)
            {
                testPosition = startPosition;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("startPosition");
            }

            if (input.Length == 0) // remove character at position.
            {
                return RemoveAt( startPosition, endPosition, out testPosition, out resultHint );
            }
        
            // If replacing the entire text with a same-lenght text, we are just setting (not replacing) the test string to the new value;
            // in this case we just call SetString.
            // If the text length is different than the specified range we would need to remove or insert characters; there are three possible
            // cases as follows:
            // 1. The text length is the same as edit positions in the range (or no assigned chars): just replace the text, no additional operations needed.
            // 2. The text is shorter: replace the text in the text string and remove (range - text.Length) characters.
            // 3. The text is larger: replace range count characters and insert (range - text.Length) characters.
            
            // Test input string first and get the last test position to determine what to do.
            if( !TestString( input, startPosition, out testPosition, out resultHint ))
            {
                return false;
            }

            if (this.assignedCharCount > 0)
            {
                // cache out params to preserve the ones from the primary operation (in case of success).
                int tempPos;
                MaskedTextResultHint tempHint;

                if (testPosition < endPosition) // Case 2. Replace + Remove.
                {
                    // Test removing remaining characters.
                    if (!RemoveAtInt(testPosition + 1, endPosition, out tempPos, out tempHint, /*testOnly*/ false))
                    {
                        testPosition = tempPos;
                        resultHint = tempHint;
                        return false;
                    }

                    // If current result hint is not success (no effect), and character shifting is actually performed, hint = side effect.
                    if (tempHint == MaskedTextResultHint.Success && resultHint != tempHint)
                    {
                        resultHint = MaskedTextResultHint.SideEffect;
                    }
                }
                else if (testPosition > endPosition) // Case 3. Replace + Insert.
                {
                    // Test shifting existing characters to make room for inserting part of the input.
                    int lastAssignedPos = this.LastAssignedPosition;
                    int dstPos = testPosition + 1;
                    int srcPos = endPosition + 1;

                    while (true)
                    {
                        srcPos = FindEditPositionFrom(srcPos, forward);
                        dstPos = FindEditPositionFrom(dstPos, forward);

                        if (dstPos == invalidIndex)
                        {
                            testPosition = this.testString.Length;
                            resultHint = MaskedTextResultHint.UnavailableEditPosition;
                            return false;
                        }

                        if (!TestChar(this.testString[srcPos], dstPos, out tempHint))
                        {
                            testPosition = dstPos;
                            resultHint = tempHint;
                            return false;
                        }

                        // If current result hint is not success (no effect), and character shifting is actually performed, hint = success effect.
                        if (tempHint == MaskedTextResultHint.Success && resultHint != tempHint)
                        {
                            resultHint = MaskedTextResultHint.Success;
                        }

                        if (srcPos == lastAssignedPos)
                        {
                            break;
                        }

                        srcPos++;
                        dstPos++;
                    }

                    // shift test passed, now do it.

                    while (dstPos > testPosition)
                    {
                        SetChar(this.testString[srcPos], dstPos);

                        srcPos = FindEditPositionFrom(srcPos - 1, backward);
                        dstPos = FindEditPositionFrom(dstPos - 1, backward);
                    }
                }
                // else endPosition == testPosition, this means replacing the entire text which is the same as Set().
            }

            // in all cases we need to replace the input.
            SetString( input, startPosition );
            return true;
        }
示例#10
0
        /// <devdoc>
        ///     Replaces the character at the first edit position from the one specified with the first character in the input;
        ///     the rest of the characters in the input will be placed in the test string according to the InsertMode (insert/replace),
        ///     shifting characters at upper positions (if any) to make room for the entire input.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Replace(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (position < 0 || position >= this.testString.Length)
            {
                testPosition = position;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("position");
            }

            if (input.Length == 0) // remove the character at position.
            {
                return RemoveAt(position, position, out testPosition, out resultHint );
            }

            // At this point, we are replacing characters with the ones in the input.

            if (!TestSetString(input, position, out testPosition, out resultHint))
            {
                return false;
            }

            return true;
        }
示例#11
0
        /// <devdoc>
        ///     Replaces the first editable character in the test string from the specified position, with the specified 
        ///     character and removes any remaining characters in the range unless the character at the specified position 
        ///     is to be escaped.
        ///     If specified range covers more than one assigned edit character, shift-left is performed after replacing
        ///     the first character.  This is useful when in a edit box the user selects text and types a character to replace it.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Replace(char input, int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (endPosition >= this.testString.Length)
            {
                testPosition = endPosition;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("endPosition");
            }

            if (startPosition < 0 || startPosition > endPosition)
            {
                testPosition = startPosition;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("startPosition");
            }

            if (startPosition == endPosition)
            {
                testPosition = startPosition;
                return TestSetChar(input, startPosition, out resultHint);
            }

            return Replace( input.ToString(), startPosition, endPosition, out testPosition, out resultHint );
        }
示例#12
0
        /// <devdoc>
        ///     Replaces the first editable character in the test string from the specified position, with the specified 
        ///     character, unless the character at the specified position is to be escaped.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Replace(char input, int position, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (position < 0 || position >= this.testString.Length)
            {
                testPosition = position;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("position");
            }

            testPosition = position;

            // If character is not to be escaped, we need to find the first edit position to test it in.
            if (!TestEscapeChar( input, testPosition ))
            {
                testPosition = FindEditPositionFrom( testPosition, forward );
            }

            if (testPosition == invalidIndex)
            {
                resultHint   = MaskedTextResultHint.UnavailableEditPosition;
                testPosition = position;
                return false;
            }

            if (!TestSetChar(input, testPosition, out resultHint))
            {
                return false;
            }

            return true;
        }
示例#13
0
        /// <devdoc>
        ///     Removes all characters in edit position from in the test string at the specified start and end positions 
        ///     and shifts any remaining characters left.
        ///     If testOnly parameter is set to false and the test passes it performs the operations on the characters.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        private bool RemoveAtInt(int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint, bool testOnly)
        {
            Debug.Assert(startPosition >= 0 && startPosition <= endPosition && endPosition < this.testString.Length, "Out of range input value.");

            // Check if we need to shift characters left to occupied the positions left by the characters being removed.
            int lastAssignedPos = this.LastAssignedPosition;
            int dstPos          = FindEditPositionInRange(startPosition, endPosition, forward); // first edit position in range.

            resultHint = MaskedTextResultHint.NoEffect;

            if (dstPos == invalidIndex || dstPos > lastAssignedPos) // nothing to remove.
            {
                testPosition = startPosition;
                return true;
            }

            testPosition = startPosition;    // On remove range, testPosition remains the same as startPosition.

            bool shiftNeeded = endPosition < lastAssignedPos; // last assigned position is upper.

            // if there are assigned characters to be removed (could be that the range doesn't have one, in such case we may be just 
            // be shifting chars), the result hint is success, let's check.
            if (FindAssignedEditPositionInRange(startPosition, endPosition, forward) != invalidIndex)
            {
                resultHint = MaskedTextResultHint.Success;
            }

            if (shiftNeeded)
            {
                // Test shifting characters.

                int srcPos = FindEditPositionFrom(endPosition + 1, forward);  // first position to shift left.
                int shiftStart = srcPos; // cache it here so we don't have to search for it later if needed.
                MaskedTextResultHint testHint;

                startPosition = dstPos; // actual start position.

                while(true)
                {
                    char srcCh = this.testString[srcPos];
                    CharDescriptor chDex = this.stringDescriptor[srcPos];
                    
                    // if the shifting character is the prompt and it is at an unassigned position we don't need to test it.
                    if (srcCh != this.PromptChar || chDex.IsAssigned)
                    {
                        if (!TestChar(srcCh, dstPos, out testHint))
                        {
                            resultHint   = testHint;
                            testPosition = dstPos; // failed position.
                            return false;
                        }
                    }

                    if (srcPos == lastAssignedPos)
                    {
                        break;
                    }

                    srcPos = FindEditPositionFrom( srcPos + 1, forward);
                    dstPos = FindEditPositionFrom( dstPos + 1, forward);
                }

                // shifting characters is a resultHint == sideEffect, update hint if no characters removed (which would be hint == success).
                if( MaskedTextResultHint.SideEffect > resultHint )
                {
                    resultHint = MaskedTextResultHint.SideEffect;
                }

                if (testOnly)
                {
                    return true; // test completed.
                }

                // test passed so shift characters.
                srcPos = shiftStart;
                dstPos = startPosition;

                while(true)
                {
                    char srcCh = this.testString[srcPos];
                    CharDescriptor chDex = this.stringDescriptor[srcPos];
                    
                    // if the shifting character is the prompt and it is at an unassigned position we just reset the destination position.
                    if (srcCh == this.PromptChar && !chDex.IsAssigned)
                    {
                        ResetChar(dstPos);
                    }
                    else
                    {
                        SetChar(srcCh, dstPos);
                        ResetChar( srcPos );
                    }

                    if (srcPos == lastAssignedPos)
                    {
                        break;
                    }

                    srcPos = FindEditPositionFrom( srcPos + 1, forward );
                    dstPos = FindEditPositionFrom( dstPos + 1, forward );
                }

                // If shifting character are less than characters to remove in the range, we need to remove the remaining ones in the range; 
                // update startPosition and ResetString belwo will take care of that.
                startPosition = dstPos + 1;
            }

            if( startPosition <= endPosition )
            {
                ResetString(startPosition, endPosition);
            }

            return true;
        }
示例#14
0
        /// <devdoc>
        ///     Removes all characters in edit position from in the test string at the specified start and end positions 
        ///     and shifts any remaining characters left.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool RemoveAt(int startPosition, int endPosition, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (endPosition >= this.testString.Length)
            {
                testPosition = endPosition;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("endPosition");
            }

            if (startPosition < 0 || startPosition > endPosition)
            {
                testPosition = startPosition;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("startPosition");
            }

            return RemoveAtInt(startPosition, endPosition, out testPosition, out resultHint, /*testOnly*/ false);
        }
示例#15
0
        /// <devdoc>
        ///     Removes the last character from the formatted string. (Remove last character in virtual string).
        ///     On exit the out param contains the position where the operation was actually performed.
        ///     This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Remove(out int testPosition, out MaskedTextResultHint resultHint)
        {
            int lastAssignedPos = this.LastAssignedPosition;

            if (lastAssignedPos == invalidIndex)
            {
                testPosition = 0;
                resultHint = MaskedTextResultHint.NoEffect;
                return true; // nothing to remove.
            }

            ResetChar(lastAssignedPos);

            testPosition = lastAssignedPos;
            resultHint   = MaskedTextResultHint.Success;

            return true;
        }
示例#16
0
        /// <devdoc>
        ///     Attempts to add the specified charactert to the last unoccupied positions in the test string (append text to 
        ///     the virtual string).
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful,
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives a hint about the operation result reason.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Add( char input, out int testPosition, out MaskedTextResultHint resultHint )
        {
            int lastAssignedPos = this.LastAssignedPosition;

            if( lastAssignedPos == this.testString.Length - 1 )    // at the last edit char position.
            {
                testPosition = this.testString.Length;
                resultHint = MaskedTextResultHint.UnavailableEditPosition;
                return false;
            }

            // Get position after last assigned position.
            testPosition = lastAssignedPos + 1;
            testPosition = FindEditPositionFrom( testPosition, forward );

            if( testPosition == invalidIndex )
            {
                resultHint = MaskedTextResultHint.UnavailableEditPosition;
                testPosition = this.testString.Length;
                return false;
            }

            if( !TestSetChar( input, testPosition, out resultHint ) )
            {
                return false;
            }

            return true;
        }
示例#17
0
        /// <devdoc>
        ///     Attempts to add the characters in the specified string to the last unoccupied positions in the test string
        ///     (append text to the virtual string).
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives a hint about the operation result reason.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool Add( string input, out int testPosition, out MaskedTextResultHint resultHint )
        {
            if( input == null )
            {
                throw new ArgumentNullException( "input" );
            }

            testPosition = this.LastAssignedPosition + 1;
            
            if( input.Length == 0 ) // nothing to add.
            {
                // Get position where the test would be performed.
                resultHint = MaskedTextResultHint.NoEffect;
                return true;    
            }

            return TestSetString(input, testPosition, out testPosition, out resultHint);
        }
示例#18
0
        /// <devdoc>
        ///     Sets the edit characters in the test string to the ones specified in the input string if all characters
        ///     are valid.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     If passwordChar is assigned, it is rendered in the output string instead of the user-supplied values.
        /// </devdoc>
        public bool Set(string input, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            resultHint = MaskedTextResultHint.Unknown;
            testPosition = 0;

            if (input.Length == 0) // Clearing the input text.
            {
                Clear(out resultHint);
                return true;
            }

            if (!TestSetString(input, testPosition, out testPosition, out resultHint))
            {
                return false;
            }

            // Reset remaining characters (if any).
            int resetPos = FindAssignedEditPositionFrom(testPosition + 1, forward);

            if (resetPos != invalidIndex)
            {
                ResetString(resetPos, this.testString.Length - 1);
            }

            return true;
        }
    public static bool GetOperationResultFromHint(MaskedTextResultHint hint)
    {
      Contract.Ensures(Contract.Result<bool>() == (hint > ((System.ComponentModel.MaskedTextResultHint)(0))));

      return default(bool);
    }
示例#20
0
        /// <devdoc>
        ///     Tests whether the character at the specified position in the test string can be set to the specified
        ///     value.
        ///     The position specified is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        private bool TestChar(char input, int position, out MaskedTextResultHint resultHint)
        {
            // boundary checks are performed in the public methods.
            Debug.Assert(position >= 0 && position < this.testString.Length, "Position out of range.");

            if (!IsPrintableChar(input))
            {
                resultHint = MaskedTextResultHint.InvalidInput;
                return false;
            }

            // Get the character info from the char descriptor table.
            CharDescriptor charDex = this.stringDescriptor[position];

            // Test if character should be escaped.
            // Test literals first - See VSW#454461.  See commented-out method SynchronizeInputOptions()

            if (IsLiteralPosition(charDex))
            {
                if (this.SkipLiterals && (input == this.testString[position]))
                {
                    resultHint = MaskedTextResultHint.CharacterEscaped;
                    return true;
                }

                resultHint = MaskedTextResultHint.NonEditPosition;
                return false;
            }

            if (input == this.promptChar )
            {
                if( this.ResetOnPrompt )
                {
                    if (IsEditPosition(charDex) && charDex.IsAssigned) // Position would be reset.
                    {
                        resultHint = MaskedTextResultHint.SideEffect;
                    }
                    else
                    {
                        resultHint = MaskedTextResultHint.CharacterEscaped;
                    }
                    return true; // test does not fail for prompt when it is to be scaped.
                }

                // Escaping precedes AllowPromptAsInput. Now test for it.
                if( !this.AllowPromptAsInput )
                {
                    resultHint = MaskedTextResultHint.PromptCharNotAllowed;
                    return false;
                }
            }

            if( input == spaceChar && this.ResetOnSpace )
            {
                if( IsEditPosition(charDex) && charDex.IsAssigned ) // Position would be reset.
                {
                    resultHint = MaskedTextResultHint.SideEffect;
                }
                else
                {
                    resultHint = MaskedTextResultHint.CharacterEscaped;
                }
                return true;
            }


            // Character was not escaped, now test it against the mask.

            // Test the character against the mask constraints.  The switch tests false conditions.
            // Space char succeeds the test if the char type is optional.
            switch (this.mask[charDex.MaskPosition])
            {
                case '#':   // digit or plus/minus sign optional.
                    if (!Char.IsDigit(input) && (input != '-') && (input != '+') && input != spaceChar)
                    {
                        resultHint = MaskedTextResultHint.DigitExpected;
                        return false;
                    }
                    break;

                case '0':   // digit required.
                    if (!Char.IsDigit(input))
                    {
                        resultHint = MaskedTextResultHint.DigitExpected;
                        return false;
                    }
                    break;

                case '9':   // digit optional.
                    if (!Char.IsDigit(input) && input != spaceChar)
                    {
                        resultHint = MaskedTextResultHint.DigitExpected;
                        return false;
                    }
                    break;

                case 'L':   // letter required.
                    if (!Char.IsLetter(input))
                    {
                        resultHint = MaskedTextResultHint.LetterExpected;
                        return false;
                    }
                    if (!IsAsciiLetter(input) && this.AsciiOnly)
                    {
                        resultHint = MaskedTextResultHint.AsciiCharacterExpected;
                        return false;
                    }
                    break;

                case '?':   // letter optional.
                    if (!Char.IsLetter(input) && input != spaceChar)
                    {
                        resultHint = MaskedTextResultHint.LetterExpected;
                        return false;
                    }
                    if (!IsAsciiLetter(input) && this.AsciiOnly)
                    {
                        resultHint = MaskedTextResultHint.AsciiCharacterExpected;
                        return false;
                    }
                    break;

                case '&':   // any character required.
                    if (!IsAscii(input) && this.AsciiOnly)
                    {
                        resultHint = MaskedTextResultHint.AsciiCharacterExpected;
                        return false;
                    }
                    break;

                case 'C':   // any character optional.
                    if ((!IsAscii(input) && this.AsciiOnly) && input != spaceChar)
                    {
                        resultHint = MaskedTextResultHint.AsciiCharacterExpected;
                        return false;
                    }
                    break;

                case 'A':   // Alphanumeric required.
                    if (!IsAlphanumeric(input))
                    {
                        resultHint = MaskedTextResultHint.AlphanumericCharacterExpected;
                        return false;
                    }
                    if (!IsAciiAlphanumeric(input) && this.AsciiOnly)
                    {
                        resultHint = MaskedTextResultHint.AsciiCharacterExpected;
                        return false;
                    }
                    break;

                case 'a':   // Alphanumeric optional.
                    if (!IsAlphanumeric(input) && input != spaceChar)
                    {
                        resultHint = MaskedTextResultHint.AlphanumericCharacterExpected;
                        return false;
                    }
                    if (!IsAciiAlphanumeric(input) && this.AsciiOnly)
                    {
                        resultHint = MaskedTextResultHint.AsciiCharacterExpected;
                        return false;
                    }
                    break;

                default:
                    Debug.Fail("Invalid mask language character.");
                    break;
            }

            // Test passed.

            if (input == this.testString[position] && charDex.IsAssigned)  // setting char would not make any difference
            {
                resultHint = MaskedTextResultHint.NoEffect;
            }
            else
            {
                resultHint = MaskedTextResultHint.Success;
            }

            return true;
        }
    public bool Remove(out int testPosition, out MaskedTextResultHint resultHint)
    {
      Contract.Ensures(((System.ComponentModel.MaskedTextResultHint)(2)) <= Contract.ValueAtReturn(out resultHint));
      Contract.Ensures(0 <= Contract.ValueAtReturn(out testPosition));
      Contract.Ensures(Contract.Result<bool>() == true);
      Contract.Ensures(Contract.ValueAtReturn(out resultHint) <= ((System.ComponentModel.MaskedTextResultHint)(4)));

      testPosition = default(int);
      resultHint = default(MaskedTextResultHint);

      return default(bool);
    }
示例#22
0
        /// <devdoc>
        ///     Tests if the character at the specified position in the test string can be set to the value specified,
        ///     and sets the character to that value if the test is successful.
        ///     The position specified is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        private bool TestSetChar(char input, int position, out MaskedTextResultHint resultHint)
        {
            if (TestChar(input, position, out resultHint))
            {
                if( resultHint == MaskedTextResultHint.Success || resultHint == MaskedTextResultHint.SideEffect ) // the character is not to be escaped.
                {
                    SetChar(input, position);
                }

                return true;
            }

            return false;
        }
    public bool VerifyChar(char input, int position, out MaskedTextResultHint hint)
    {
      Contract.Ensures(((System.ComponentModel.MaskedTextResultHint)(-55)) <= Contract.ValueAtReturn(out hint));
      Contract.Ensures(Contract.ValueAtReturn(out hint) <= ((System.ComponentModel.MaskedTextResultHint)(4)));

      hint = default(MaskedTextResultHint);

      return default(bool);
    }
示例#24
0
        /// <devdoc>
        ///     Test the characters in the specified string agaist the test string, starting from the specified position.
        ///     If the test is successful, the characters in the test string are set appropriately.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        private bool TestSetString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (TestString(input, position, out testPosition, out resultHint))
            {
                SetString(input, position);
                return true;
            }

            return false;
        }
示例#25
0
        /// <devdoc>
        ///     Test the characters in the specified string agaist the test string, starting from the specified position.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The successCount out param contains the number of characters that would be actually set (not escaped).
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        private bool TestString(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
        {
            Debug.Assert(input != null, "null input.");
            Debug.Assert( position >= 0, "Position out of range." );

            resultHint = MaskedTextResultHint.Unknown;
            testPosition = position;

            if( input.Length == 0 )
            {
                return true;
            }

            // If any char is actually accepted, then the hint is success, otherwise whatever the last character result is.
            // Need a temp variable for this.
            MaskedTextResultHint tempHint = resultHint;
            
            foreach( char ch in input )
            {
                if( testPosition >= this.testString.Length )
                {
                    resultHint = MaskedTextResultHint.UnavailableEditPosition;
                    return false;
                }
                
                // If character is not to be escaped, we need to find an edit position to test it in.
                if( !TestEscapeChar(ch, testPosition) )
                {
                    testPosition = FindEditPositionFrom( testPosition, forward );
                    
                    if( testPosition == invalidIndex )
                    {
                        testPosition = this.testString.Length;
                        resultHint   = MaskedTextResultHint.UnavailableEditPosition;
                        return false;
                    }
                }

                // Test/Set char will scape prompt, space and literals if needed.
                if( !TestChar( ch, testPosition, out tempHint ) )
                {
                    resultHint = tempHint;
                    return false;
                }

                // Result precedence: Success, SideEffect, NoEffect, CharacterEscaped.
                if( tempHint > resultHint )
                {
                    resultHint = tempHint;
                }

                testPosition++;
            }

            testPosition--;

            return true;
        }
示例#26
0
        /// <devdoc>
        ///     Tests whether the specified character would be set successfully at the specified position.
        /// </devdoc>
        public bool VerifyChar(char input, int position, out MaskedTextResultHint hint)
        {
            hint = MaskedTextResultHint.NoEffect;

            if (position < 0 || position >= this.testString.Length)
            {
                hint = MaskedTextResultHint.PositionOutOfRange;
                return false;
            }

            return TestChar(input, position, out hint);
        }
		public MaskInputRejectedEventArgs (int position, MaskedTextResultHint rejectionHint) : base ()
		{
			this.position = position;
			this.rejection_hint = rejectionHint;
		}
示例#28
0
        /// <devdoc>
        ///     Verifies the test string against the mask.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool VerifyString(string input, out int testPosition, out MaskedTextResultHint resultHint)
        {
            testPosition = 0;

            if( input == null || input.Length == 0 ) // nothing to verify.
            {
                resultHint = MaskedTextResultHint.NoEffect;
                return true;  
            }

            return TestString(input, 0, out testPosition, out resultHint);
        }
        /// <devdoc>
        ///     Override version to be able to perform the operation on a cloned provider.
        /// </devdoc>
        private bool PlaceChar(MaskedTextProvider provider, char ch, int startPosition, int length, bool overwrite, 
            out MaskedTextResultHint hint)
        {
            Debug.Assert( !this.flagState[IS_NULL_MASK], "This method must be called when a Mask is provided." );

            this.caretTestPos = startPosition;

            if (startPosition < this.maskedTextProvider.Length)
            {
                if (length > 0)  // Replacing selection with input char.
                {
                    int endPos = startPosition + length - 1;
                    return provider.Replace(ch, startPosition, endPos, out this.caretTestPos, out hint);
                }
                else
                {
                    if (overwrite)
                    {
                        // overwrite character at next edit position from startPosition (inclusive).
                        return provider.Replace(ch, startPosition, out this.caretTestPos, out hint);
                    }
                    else // insert.
                    {
                        return provider.InsertAt(ch, startPosition, out this.caretTestPos, out hint);
                    }
                }
            }

            hint = MaskedTextResultHint.UnavailableEditPosition;
            return false;
        }
示例#30
0
        /// <devdoc>
        ///     Attempts to insert the characters in the specified string in at the specified position in the test string,
        ///     shifting characters at upper positions (if any) to make room for the input.
        ///     On exit the testPosition contains last position where the primary operation was actually performed if successful, 
        ///     otherwise the first position that made the test fail. This position is relative to the test string.
        ///     The MaskedTextResultHint out param gives more information about the operation result.
        ///     Returns true on success, false otherwise.
        /// </devdoc>
        public bool InsertAt(string input, int position, out int testPosition, out MaskedTextResultHint resultHint)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (position < 0 || position >= this.testString.Length)
            {
                testPosition = position;
                resultHint   = MaskedTextResultHint.PositionOutOfRange;
                return false;
                //throw new ArgumentOutOfRangeException("position");
            }

            return InsertAtInt(input, position, out testPosition, out resultHint, false);
        }