예제 #1
0
        public void Clear()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            maskedTextProvider.Add("12");
            Assert.Equal(2, maskedTextProvider.AssignedEditPositionCount);

            maskedTextProvider.Clear();
            Assert.Equal(0, maskedTextProvider.AssignedEditPositionCount);
        }
예제 #2
0
        public void FindAssignedEditPositionInRange()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            Assert.Equal(-1, maskedTextProvider.FindAssignedEditPositionInRange(0, 1, true));

            maskedTextProvider.Add("12");
            Assert.Equal(0, maskedTextProvider.FindAssignedEditPositionInRange(0, 1, true));
            Assert.Equal(2, maskedTextProvider.FindAssignedEditPositionInRange(0, 5, false));
        }
예제 #3
0
        public void Clear_MaskedTextResultHint()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            maskedTextProvider.Clear(out MaskedTextResultHint resultHint);
            Assert.Equal(MaskedTextResultHint.NoEffect, resultHint);

            maskedTextProvider.Add("12");
            Assert.Equal(2, maskedTextProvider.AssignedEditPositionCount);

            maskedTextProvider.Clear(out resultHint);
            Assert.Equal(MaskedTextResultHint.Success, resultHint);
            Assert.Equal(0, maskedTextProvider.AssignedEditPositionCount);
        }
예제 #4
0
        protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            if (StayInFocusUntilValid)
            {
                _mprovider.Clear();
                _mprovider.Add(this.Text);
                if (!_mprovider.MaskFull)
                {
                    e.Handled = true;
                }
            }

            base.OnPreviewLostKeyboardFocus(e);
        }
예제 #5
0
 private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType)
 {
     if (this.listViewCannedMasks.IsHandleCreated)
     {
         MaskDescriptor maskDex = null;
         if (this.listViewCannedMasks.SelectedItems.Count > 0)
         {
             int num = this.listViewCannedMasks.SelectedIndices[0];
             maskDex = this.maskDescriptors[num];
         }
         this.maskDescriptors.RemoveAt(this.maskDescriptors.Count - 1);
         this.maskDescriptors.Sort(new MaskDescriptorComparer(sortType, this.listViewSortOrder));
         System.Design.UnsafeNativeMethods.SendMessage(this.listViewCannedMasks.Handle, 11, false, 0);
         try
         {
             this.listViewCannedMasks.Items.Clear();
             string str = System.Design.SR.GetString("MaskDescriptorValidatingTypeNone");
             foreach (MaskDescriptor descriptor2 in this.maskDescriptors)
             {
                 string             str2     = (descriptor2.ValidatingType != null) ? descriptor2.ValidatingType.Name : str;
                 MaskedTextProvider provider = new MaskedTextProvider(descriptor2.Mask, descriptor2.Culture);
                 provider.Add(descriptor2.Sample);
                 string str3 = provider.ToString(false, true);
                 this.listViewCannedMasks.Items.Add(new ListViewItem(new string[] { descriptor2.Name, str3, str2 }));
             }
             this.maskDescriptors.Add(this.customMaskDescriptor);
             this.listViewCannedMasks.Items.Add(new ListViewItem(new string[] { this.customMaskDescriptor.Name, "", str }));
             if (maskDex != null)
             {
                 this.SetSelectedMaskDescriptor(maskDex);
             }
         }
         finally
         {
             System.Design.UnsafeNativeMethods.SendMessage(this.listViewCannedMasks.Handle, 11, true, 0);
             this.listViewCannedMasks.Invalidate();
         }
     }
 }
예제 #6
0
        /// <summary>
        /// Sorts the maskDescriptors and the list view items.
        /// </summary>
        private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType)
        {
            if (!_listViewCannedMasks.IsHandleCreated)
            {
                return;
            }

            MaskDescriptor selectedMaskDex = null;

            // Save current selected entry to restore it after sorting.
            if (_listViewCannedMasks.SelectedItems.Count > 0)
            {
                int selectedIndex = _listViewCannedMasks.SelectedIndices[0];
                selectedMaskDex = _maskDescriptors[selectedIndex];
            }

            // Custom mask descriptor should always be the last entry - remove it before sorting array.
            _maskDescriptors.RemoveAt(_maskDescriptors.Count - 1);

            // Sort MaskDescriptor collection.
            _maskDescriptors.Sort(new MaskDescriptorComparer(sortType, _listViewSortOrder));

            // Since we need to pre-process each item before inserting it in the ListView, it is better to remove all items
            // from it first and then add the sorted ones back (no replace).  Stop redrawing while we change the list.

            User32.SendMessageW(_listViewCannedMasks, User32.WM.SETREDRAW, (nint)BOOL.FALSE);

            try
            {
                _listViewCannedMasks.Items.Clear();

                string nullEntry = SR.MaskDescriptorValidatingTypeNone;

                foreach (MaskDescriptor maskDescriptor in _maskDescriptors)
                {
                    string validatingType = maskDescriptor.ValidatingType != null ? maskDescriptor.ValidatingType.Name : nullEntry;

                    // Make sure the sample displays literals.
                    MaskedTextProvider mtp = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
                    bool success           = mtp.Add(maskDescriptor.Sample);
                    Debug.Assert(success, "BadBad: Could not add MaskDescriptor.Sample even it was validated, something is wrong!");
                    // Don't include prompt.
                    string sample = mtp.ToString(false, true);

                    _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { maskDescriptor.Name, sample, validatingType }));
                }

                // Add the custom mask descriptor as the last entry.
                _maskDescriptors.Add(_customMaskDescriptor);
                _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { _customMaskDescriptor.Name, "", nullEntry }));

                if (selectedMaskDex != null)
                {
                    SetSelectedMaskDescriptor(selectedMaskDex);
                }
            }
            finally
            {
                // Resume redraw.
                User32.SendMessageW(_listViewCannedMasks, User32.WM.SETREDRAW, (nint)BOOL.TRUE);
                _listViewCannedMasks.Invalidate();
            }
        }
예제 #7
0
        public void Add_String_Input_False()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            Assert.False(maskedTextProvider.Add("TT"));
        }
예제 #8
0
        public void Add_Char_Input_False()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            Assert.False(maskedTextProvider.Add('T'));
        }
예제 #9
0
        /// <summary>
        /// Sorts the maskDescriptors and the list view items.
        /// </summary>
        private void UpdateSortedListView(MaskDescriptorComparer.SortType sortType)
        {
            if (!_listViewCannedMasks.IsHandleCreated)
            {
                return;
            }

            MaskDescriptor selectedMaskDex = null;

            // Save current selected entry to restore it after sorting.
            if (_listViewCannedMasks.SelectedItems.Count > 0)
            {
                int selectedIndex = _listViewCannedMasks.SelectedIndices[0];
                selectedMaskDex = _maskDescriptors[selectedIndex];
            }

            // Custom mask descriptor should always be the last entry - remove it before sorting array.
            _maskDescriptors.RemoveAt(_maskDescriptors.Count - 1);

            // Sort MaskDescriptor collection.
            _maskDescriptors.Sort(new MaskDescriptorComparer(sortType, _listViewSortOrder));

            // Sorting the ListView items forces handle recreation, since we have the items sorted and know what item to select
            // it is better for us to replace the items ourselves.  This way also avoids problems with the selected item  and
            // the custom entry not getting properly added.
            // this.listViewCannedMasks.Sort();

            // Since we need to pre-process each item before inserting it in the ListView, it is better to remove all items
            // from it first and then add the sorted ones back (no replace).  Stop redrawing while we change the list.

            UnsafeNativeMethods.SendMessage(_listViewCannedMasks.Handle, Interop.WindowMessages.WM_SETREDRAW, false, /* unused = */ 0);

            try
            {
                _listViewCannedMasks.Items.Clear();

                string nullEntry = SR.MaskDescriptorValidatingTypeNone;

                foreach (MaskDescriptor maskDescriptor in _maskDescriptors)
                {
                    string validatingType = maskDescriptor.ValidatingType != null ? maskDescriptor.ValidatingType.Name : nullEntry;

                    // Make sure the sample displays literals.
                    MaskedTextProvider mtp = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
                    bool success           = mtp.Add(maskDescriptor.Sample);
                    Debug.Assert(success, "BadBad: Could not add MaskDescriptor.Sample even it was validated, something is wrong!");
                    // Don't include prompt.
                    string sample = mtp.ToString(false, true);

                    _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { maskDescriptor.Name, sample, validatingType }));
                }

                // Add the custom mask descriptor as the last entry.
                _maskDescriptors.Add(_customMaskDescriptor);
                _listViewCannedMasks.Items.Add(new ListViewItem(new string[] { _customMaskDescriptor.Name, "", nullEntry }));

                if (selectedMaskDex != null)
                {
                    SetSelectedMaskDescriptor(selectedMaskDex);
                }
            }
            finally
            {
                // Resume redraw.
                UnsafeNativeMethods.SendMessage(_listViewCannedMasks.Handle, Interop.WindowMessages.WM_SETREDRAW, true, /* unused = */ 0);
                _listViewCannedMasks.Invalidate();
            }
        }