public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor, out string validationErrorDescription)
 {
     validationErrorDescription = string.Empty;
     if (maskDescriptor == null)
     {
         validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNull");
         return false;
     }
     if ((string.IsNullOrEmpty(maskDescriptor.Mask) || string.IsNullOrEmpty(maskDescriptor.Name)) || string.IsNullOrEmpty(maskDescriptor.Sample))
     {
         validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNullOrEmptyRequiredProperty");
         return false;
     }
     MaskedTextProvider maskedTextProvider = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
     MaskedTextBox box = new MaskedTextBox(maskedTextProvider) {
         SkipLiterals = true,
         ResetOnPrompt = true,
         ResetOnSpace = true,
         ValidatingType = maskDescriptor.ValidatingType,
         FormatProvider = maskDescriptor.Culture,
         Culture = maskDescriptor.Culture
     };
     box.TypeValidationCompleted += new TypeValidationEventHandler(MaskDescriptor.maskedTextBox1_TypeValidationCompleted);
     box.MaskInputRejected += new MaskInputRejectedEventHandler(MaskDescriptor.maskedTextBox1_MaskInputRejected);
     box.Text = maskDescriptor.Sample;
     if ((box.Tag == null) && (maskDescriptor.ValidatingType != null))
     {
         box.ValidateText();
     }
     if (box.Tag != null)
     {
         validationErrorDescription = box.Tag.ToString();
     }
     return (validationErrorDescription.Length == 0);
 }
예제 #2
0
        /// <summary>
        /// Selects the mask descriptor corresponding to the current MaskedTextBox.Mask if any, otherwise the custom entry.
        /// </summary>
        private void SelectMtbMaskDescriptor()
        {
            int selectedItemIdx = -1;

            if (!string.IsNullOrEmpty(_maskedTextBox.Mask))
            {
                for (int selectedIndex = 0; selectedIndex < _maskDescriptors.Count; selectedIndex++)
                {
                    MaskDescriptor descriptor = _maskDescriptors[selectedIndex];

                    if (descriptor.Mask == _maskedTextBox.Mask && descriptor.ValidatingType == _maskedTextBox.ValidatingType)
                    {
                        selectedItemIdx = selectedIndex;
                        break;
                    }
                }
            }

            if (selectedItemIdx == -1) // select custom mask.
            {
                selectedItemIdx = GetMaskDescriptorIndex(_customMaskDescriptor);

                if (selectedItemIdx == -1)
                {
                    Debug.Fail("Could not find custom mask descriptor.");
                }
            }

            if (selectedItemIdx != -1)
            {
                SetSelectedMaskDescriptor(selectedItemIdx);
            }
        }
예제 #3
0
        private void SelectMtbMaskDescriptor()
        {
            int maskDexIndex = -1;

            if (!string.IsNullOrEmpty(this.maskedTextBox.Mask))
            {
                for (int i = 0; i < this.maskDescriptors.Count; i++)
                {
                    MaskDescriptor descriptor = this.maskDescriptors[i];
                    if ((descriptor.Mask == this.maskedTextBox.Mask) && (descriptor.ValidatingType == this.maskedTextBox.ValidatingType))
                    {
                        maskDexIndex = i;
                        break;
                    }
                }
            }
            if (maskDexIndex == -1)
            {
                maskDexIndex = this.GetMaskDescriptorIndex(this.customMaskDescriptor);
            }
            if (maskDexIndex != -1)
            {
                this.SetSelectedMaskDescriptor(maskDexIndex);
            }
        }
예제 #4
0
        /// <summary>
        /// Uses the specified ITypeDiscoveryService service provider to discover MaskDescriptor objects from
        /// the referenced assemblies.
        /// </summary>
        public void DiscoverMaskDescriptors(ITypeDiscoveryService discoveryService)
        {
            if (discoveryService is null)
            {
                return;
            }

            ICollection descriptors = DesignerUtils.FilterGenericTypes(discoveryService.GetTypes(typeof(MaskDescriptor), false /* excludeGlobalTypes */));

            // Note: This code assumes DesignerUtils.FilterGenericTypes return a valid ICollection (collection of MaskDescriptor types).
            foreach (Type t in descriptors)
            {
                if (t.IsAbstract || !t.IsPublic)
                {
                    continue;
                }

                // Since mask descriptors can be provided from external sources, we need to guard against
                // possible exceptions when accessing an external descriptor.
                try
                {
                    MaskDescriptor maskDescriptor = (MaskDescriptor)Activator.CreateInstance(t);
                    InsertMaskDescriptor(0, maskDescriptor);
                }
                catch (Exception ex)
                {
                    if (ClientUtils.IsCriticalException(ex))
                    {
                        throw;
                    }
                }
            }
        }
예제 #5
0
        private void RemoveMaskDescriptor(MaskDescriptor maskDescriptor)
        {
            int maskDescriptorIndex = this.GetMaskDescriptorIndex(maskDescriptor);

            if (maskDescriptorIndex >= 0)
            {
                this.maskDescriptors.RemoveAt(maskDescriptorIndex);
            }
        }
예제 #6
0
        private void InsertMaskDescriptor(int index, MaskDescriptor maskDescriptor, bool validateDescriptor)
        {
            string str;

            if ((!validateDescriptor || MaskDescriptor.IsValidMaskDescriptor(maskDescriptor, out str)) && !this.ContainsMaskDescriptor(maskDescriptor))
            {
                this.maskDescriptors.Insert(index, maskDescriptor);
            }
        }
예제 #7
0
        public override bool Equals(object maskDescriptor)
        {
            MaskDescriptor descriptor = maskDescriptor as MaskDescriptor;

            if (!IsValidMaskDescriptor(descriptor) || !IsValidMaskDescriptor(this))
            {
                return(this == maskDescriptor);
            }
            return((this.Mask == descriptor.Mask) && (this.ValidatingType == descriptor.ValidatingType));
        }
 private void AddDefaultMaskDescriptors(CultureInfo culture)
 {
     this.customMaskDescriptor = new MaskDescriptorTemplate(null, System.Design.SR.GetString("MaskDesignerDialogCustomEntry"), null, null, null, true);
     List<MaskDescriptor> localizedMaskDescriptors = MaskDescriptorTemplate.GetLocalizedMaskDescriptors(culture);
     this.InsertMaskDescriptor(0, this.customMaskDescriptor, false);
     foreach (MaskDescriptor descriptor in localizedMaskDescriptors)
     {
         this.InsertMaskDescriptor(0, descriptor);
     }
 }
예제 #9
0
        private void AddDefaultMaskDescriptors(CultureInfo culture)
        {
            this.customMaskDescriptor = new MaskDescriptorTemplate(null, System.Design.SR.GetString("MaskDesignerDialogCustomEntry"), null, null, null, true);
            List <MaskDescriptor> localizedMaskDescriptors = MaskDescriptorTemplate.GetLocalizedMaskDescriptors(culture);

            this.InsertMaskDescriptor(0, this.customMaskDescriptor, false);
            foreach (MaskDescriptor descriptor in localizedMaskDescriptors)
            {
                this.InsertMaskDescriptor(0, descriptor);
            }
        }
예제 #10
0
 private bool ContainsMaskDescriptor(MaskDescriptor maskDescriptor)
 {
     foreach (MaskDescriptor descriptor in this.maskDescriptors)
     {
         if (maskDescriptor.Equals(descriptor) || (maskDescriptor.Name.Trim() == descriptor.Name.Trim()))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #11
0
 private int GetMaskDescriptorIndex(MaskDescriptor maskDescriptor)
 {
     for (int i = 0; i < this.maskDescriptors.Count; i++)
     {
         MaskDescriptor descriptor = this.maskDescriptors[i];
         if (descriptor == maskDescriptor)
         {
             return(i);
         }
     }
     return(-1);
 }
예제 #12
0
        public MaskDescriptorTemplate(string mask, string name, string sample, Type validatingType, CultureInfo culture, bool skipValidation)
        {
            string str;

            this.mask    = mask;
            this.name    = name;
            this.sample  = sample;
            this.type    = validatingType;
            this.culture = culture;
            if (!skipValidation && !MaskDescriptor.IsValidMaskDescriptor(this, out str))
            {
                this.mask = null;
            }
        }
예제 #13
0
        private void txtBoxMask_TextChanged(object sender, EventArgs e)
        {
            MaskDescriptor descriptor = null;

            if (this.listViewCannedMasks.SelectedItems.Count != 0)
            {
                int num = this.listViewCannedMasks.SelectedIndices[0];
                descriptor = this.maskDescriptors[num];
            }
            if ((descriptor == null) || ((descriptor != this.customMaskDescriptor) && (descriptor.Mask != this.txtBoxMask.Text)))
            {
                this.SetSelectedMaskDescriptor(this.customMaskDescriptor);
            }
        }
예제 #14
0
        private void InsertMaskDescriptor(int index, MaskDescriptor maskDescriptor, bool validateDescriptor)
        {
            string errorMessage;

            if (validateDescriptor && !MaskDescriptor.IsValidMaskDescriptor(maskDescriptor, out errorMessage))
            {
                return;
            }

            if (!ContainsMaskDescriptor(maskDescriptor))
            {
                _maskDescriptors.Insert(index, maskDescriptor);
            }
        }
예제 #15
0
        /// <summary>
        /// Adds the default mask descriptors to the mask description list.
        /// We need to add the default descriptors explicitly because the DiscoverMaskDescriptors method only adds
        /// public descriptors and these are internal.
        /// </summary>
        private void AddDefaultMaskDescriptors(CultureInfo culture)
        {
            _customMaskDescriptor = new MaskDescriptorTemplate(null, SR.MaskDesignerDialogCustomEntry, null, null, null, true);

            List <MaskDescriptor> maskDescriptors = MaskDescriptorTemplate.GetLocalizedMaskDescriptors(culture);

            // Need to pass false for validateDescriptor param since the custom mask will fail validation
            // because the mask is empty.
            InsertMaskDescriptor(0, _customMaskDescriptor, /*validate*/ false);

            foreach (MaskDescriptor maskDescriptor in maskDescriptors)
            {
                InsertMaskDescriptor(0, maskDescriptor);
            }
        }
예제 #16
0
        /// <summary>
        /// Gets the index of a mask descriptor in the mask descriptor table.
        /// </summary>
        private int GetMaskDescriptorIndex(MaskDescriptor maskDescriptor)
        {
            for (int index = 0; index < _maskDescriptors.Count; index++)
            {
                MaskDescriptor descriptor = _maskDescriptors[index];

                if (descriptor == maskDescriptor)
                {
                    return(index);
                }
            }

            Debug.Fail("Could not find mask descriptor.");
            return(-1);
        }
예제 #17
0
        /// <summary>
        /// Determines whether the specified MaskDescriptor object is in the MaskDescriptor collection or not.
        /// </summary>
        private bool ContainsMaskDescriptor(MaskDescriptor maskDescriptor)
        {
            Debug.Assert(maskDescriptor != null, "Null mask descriptor.");

            foreach (MaskDescriptor descriptor in _maskDescriptors)
            {
                Debug.Assert(descriptor != null, "Null mask descriptor in the collection.");

                if (maskDescriptor.Equals(descriptor) || maskDescriptor.Name.Trim() == descriptor.Name.Trim())
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #18
0
        public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor, out string validationErrorDescription)
        {
            validationErrorDescription = string.Empty;

            if (maskDescriptor is null)
            {
                validationErrorDescription = SR.MaskDescriptorNull;
                return(false);
            }

            if (string.IsNullOrEmpty(maskDescriptor.Mask) || string.IsNullOrEmpty(maskDescriptor.Name) || string.IsNullOrEmpty(maskDescriptor.Sample))
            {
                validationErrorDescription = SR.MaskDescriptorNullOrEmptyRequiredProperty;
                return(false);
            }

            MaskedTextProvider maskedTextProvider = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
            MaskedTextBox      maskedTextBox      = new MaskedTextBox(maskedTextProvider);

            maskedTextBox.SkipLiterals             = true;
            maskedTextBox.ResetOnPrompt            = true;
            maskedTextBox.ResetOnSpace             = true;
            maskedTextBox.ValidatingType           = maskDescriptor.ValidatingType;
            maskedTextBox.FormatProvider           = maskDescriptor.Culture;
            maskedTextBox.Culture                  = maskDescriptor.Culture;
            maskedTextBox.TypeValidationCompleted += new TypeValidationEventHandler(maskedTextBox1_TypeValidationCompleted);
            maskedTextBox.MaskInputRejected       += new MaskInputRejectedEventHandler(maskedTextBox1_MaskInputRejected);

            // Add sample. If it fails we are done.
            maskedTextBox.Text = maskDescriptor.Sample;

            if (maskedTextBox.Tag is null) // Sample was added successfully (MaskInputRejected event handler did not change the maskedTextBox tag).
            {
                if (maskDescriptor.ValidatingType != null)
                {
                    maskedTextBox.ValidateText();
                }
            }

            if (maskedTextBox.Tag != null) // Validation failed.
            {
                validationErrorDescription = maskedTextBox.Tag.ToString();
            }

            return(validationErrorDescription.Length == 0);
        }
예제 #19
0
 private void listViewCannedMasks_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.listViewCannedMasks.SelectedItems.Count != 0)
     {
         int            num        = this.listViewCannedMasks.SelectedIndices[0];
         MaskDescriptor descriptor = this.maskDescriptors[num];
         if (descriptor != this.customMaskDescriptor)
         {
             this.txtBoxMask.Text              = descriptor.Mask;
             this.maskedTextBox.Mask           = descriptor.Mask;
             this.maskedTextBox.ValidatingType = descriptor.ValidatingType;
         }
         else
         {
             this.maskedTextBox.ValidatingType = null;
         }
     }
 }
예제 #20
0
        /// <summary>
        /// Mask text box TextChanged event handler.
        /// </summary>
        private void txtBoxMask_TextChanged(object sender, EventArgs e)
        {
            // If the change in the text box is performed by the user, we need to select the 'Custom' item in
            // the list view, which is the last item.

            MaskDescriptor selectedMaskDex = null;

            if (_listViewCannedMasks.SelectedItems.Count != 0)
            {
                int selectedIndex = _listViewCannedMasks.SelectedIndices[0];
                selectedMaskDex = _maskDescriptors[selectedIndex];
            }

            if (selectedMaskDex is null || (selectedMaskDex != _customMaskDescriptor && selectedMaskDex.Mask != _txtBoxMask.Text))
            {
                SetSelectedMaskDescriptor(_customMaskDescriptor);
            }
        }
        public MaskDescriptorTemplate(string mask, string name, string sample, Type validatingType, CultureInfo culture, bool skipValidation)
        {
            _mask    = mask;
            _name    = name;
            _sample  = sample;
            _type    = validatingType;
            _culture = culture;

            if (skipValidation)
            {
                return;
            }

            string msg;

            if (!MaskDescriptor.IsValidMaskDescriptor(this, out msg))
            {
                // Don't throw here, callers should check the Mask property for validity. See the ValidMaskDescriptorList below.
                _mask = null;
            }
        }
예제 #22
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();
         }
     }
 }
예제 #23
0
        /// <summary>
        /// Canned masks list view SelectedIndexChanged event handler.  Gets the selected canned mask
        /// information.
        /// </summary>
        private void listViewCannedMasks_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_listViewCannedMasks.SelectedItems.Count == 0)
            {
                return;
            }

            int            selectedIndex  = _listViewCannedMasks.SelectedIndices[0];
            MaskDescriptor maskDescriptor = _maskDescriptors[selectedIndex];

            // If one of the canned mask descriptors chosen, update test control.
            if (maskDescriptor != _customMaskDescriptor)
            {
                _txtBoxMask.Text              = maskDescriptor.Mask;
                _maskedTextBox.Mask           = maskDescriptor.Mask;
                _maskedTextBox.ValidatingType = maskDescriptor.ValidatingType;
            }
            else
            {
                _maskedTextBox.ValidatingType = null;
            }
        }
예제 #24
0
        public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor, out string validationErrorDescription)
        {
            validationErrorDescription = string.Empty;
            if (maskDescriptor == null)
            {
                validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNull");
                return(false);
            }
            if ((string.IsNullOrEmpty(maskDescriptor.Mask) || string.IsNullOrEmpty(maskDescriptor.Name)) || string.IsNullOrEmpty(maskDescriptor.Sample))
            {
                validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNullOrEmptyRequiredProperty");
                return(false);
            }
            MaskedTextProvider maskedTextProvider = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
            MaskedTextBox      box = new MaskedTextBox(maskedTextProvider)
            {
                SkipLiterals   = true,
                ResetOnPrompt  = true,
                ResetOnSpace   = true,
                ValidatingType = maskDescriptor.ValidatingType,
                FormatProvider = maskDescriptor.Culture,
                Culture        = maskDescriptor.Culture
            };

            box.TypeValidationCompleted += new TypeValidationEventHandler(MaskDescriptor.maskedTextBox1_TypeValidationCompleted);
            box.MaskInputRejected       += new MaskInputRejectedEventHandler(MaskDescriptor.maskedTextBox1_MaskInputRejected);
            box.Text = maskDescriptor.Sample;
            if ((box.Tag == null) && (maskDescriptor.ValidatingType != null))
            {
                box.ValidateText();
            }
            if (box.Tag != null)
            {
                validationErrorDescription = box.Tag.ToString();
            }
            return(validationErrorDescription.Length == 0);
        }
예제 #25
0
 public void DiscoverMaskDescriptors(ITypeDiscoveryService discoveryService)
 {
     if (discoveryService != null)
     {
         foreach (System.Type type in DesignerUtils.FilterGenericTypes(discoveryService.GetTypes(typeof(MaskDescriptor), false)))
         {
             if (!type.IsAbstract && type.IsPublic)
             {
                 try
                 {
                     MaskDescriptor maskDescriptor = (MaskDescriptor)Activator.CreateInstance(type);
                     this.InsertMaskDescriptor(0, maskDescriptor);
                 }
                 catch (Exception exception)
                 {
                     if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }
예제 #26
0
        /// <summary>
        /// Selects the specified item in the ListView.
        /// </summary>
        private void SetSelectedMaskDescriptor(MaskDescriptor maskDex)
        {
            int maskDexIndex = GetMaskDescriptorIndex(maskDex);

            SetSelectedMaskDescriptor(maskDexIndex);
        }
 private void SetSelectedMaskDescriptor(MaskDescriptor maskDex)
 {
     int maskDescriptorIndex = this.GetMaskDescriptorIndex(maskDex);
     this.SetSelectedMaskDescriptor(maskDescriptorIndex);
 }
 private void RemoveMaskDescriptor(MaskDescriptor maskDescriptor)
 {
     int maskDescriptorIndex = this.GetMaskDescriptorIndex(maskDescriptor);
     if (maskDescriptorIndex >= 0)
     {
         this.maskDescriptors.RemoveAt(maskDescriptorIndex);
     }
 }
 private void InsertMaskDescriptor(int index, MaskDescriptor maskDescriptor, bool validateDescriptor)
 {
     string str;
     if ((!validateDescriptor || MaskDescriptor.IsValidMaskDescriptor(maskDescriptor, out str)) && !this.ContainsMaskDescriptor(maskDescriptor))
     {
         this.maskDescriptors.Insert(index, maskDescriptor);
     }
 }
 private void InsertMaskDescriptor(int index, MaskDescriptor maskDescriptor)
 {
     this.InsertMaskDescriptor(index, maskDescriptor, true);
 }
 private int GetMaskDescriptorIndex(MaskDescriptor maskDescriptor)
 {
     for (int i = 0; i < this.maskDescriptors.Count; i++)
     {
         MaskDescriptor descriptor = this.maskDescriptors[i];
         if (descriptor == maskDescriptor)
         {
             return i;
         }
     }
     return -1;
 }
예제 #32
0
		public static bool IsValidMaskDescriptor (MaskDescriptor maskDescriptor)
		{
			throw new NotImplementedException ();
		}
 private bool ContainsMaskDescriptor(MaskDescriptor maskDescriptor)
 {
     foreach (MaskDescriptor descriptor in this.maskDescriptors)
     {
         if (maskDescriptor.Equals(descriptor) || (maskDescriptor.Name.Trim() == descriptor.Name.Trim()))
         {
             return true;
         }
     }
     return false;
 }
 public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor, out string validationErrorDescription)
 {
     throw new NotImplementedException();
 }
예제 #35
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();
            }
        }
예제 #36
0
 /// <summary>
 /// Determines whether the specified mask descriptor is valid and hence can be added to the canned masks list.
 /// A valid MaskDescriptor must meet the following conditions:
 /// 1. Not null.
 /// 2. Not null or empty mask.
 /// 3. Not null or empty name.
 /// 4. Not null or empty sample.
 /// 5. The sample is correct based on the mask and all required edit characters have been provided (mask completed - not necessarily full).
 /// 6. The sample is valid based on the ValidatingType object (if any).
 /// </summary>
 public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor)
 {
     return(IsValidMaskDescriptor(maskDescriptor, out string _));
 }
예제 #37
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();
            }
        }
예제 #38
0
 /// <summary>
 /// Inserts a MaskDescriptor object in the specified position in the internal MaskDescriptor collection.
 /// </summary>
 private void InsertMaskDescriptor(int index, MaskDescriptor maskDescriptor)
 {
     InsertMaskDescriptor(index, maskDescriptor, true);
 }
예제 #39
0
        private void SetSelectedMaskDescriptor(MaskDescriptor maskDex)
        {
            int maskDescriptorIndex = this.GetMaskDescriptorIndex(maskDex);

            this.SetSelectedMaskDescriptor(maskDescriptorIndex);
        }
예제 #40
0
		public static bool IsValidMaskDescriptor (MaskDescriptor maskDescriptor, out string validationErrorDescription)
		{
			throw new NotImplementedException ();
		}
 public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor)
 {
     string str;
     return IsValidMaskDescriptor(maskDescriptor, out str);
 }