Example #1
0
        protected override bool SetValueInternal(object value, ValueUpdateSource updateSource)
        {
            bool result = false;

#if _DOTNET2
            NullableConverter nc = TypeConverter as NullableConverter;
            if ((value == null) || ((value != null) && UnderlyingType.IsInstanceOfType(value)) ||
                ((nc != null) && ((value == null) || nc.UnderlyingType.IsInstanceOfType(value))))
#else
            if ((value != null) && UnderlyingType.IsInstanceOfType(value))
#endif
            {
                UnderlyingValue = value;
                result          = true;
            }

            if (updateSource != ValueUpdateSource.FromChild)
            {
                if ((mOwnerEnumerator != null) &&   // mOwnerEnumerator could be null for the boolean of Property._enabledVariable
                    !mOwnerEnumerator.Property.Value.NoLinkWithChildren)
                {
                    PropertyTypeDescriptorContext context = GetTypeDescriptorContext(OwnerEnumerator);
                    if (TypeConverter.GetPropertiesSupported(context) == false)
                    {
                        PropertyEnumerator childEnum = mOwnerEnumerator.Children;
                        if (childEnum.Count > 0)
                        {
                            string masterStr = mOwnerEnumerator.Property.Value.GetStringValue();

                            char separator = mOwnerEnumerator.Property.Value.GroupedValueSeparator;
                            while (childEnum != childEnum.RightBound)
                            {
                                masterStr.TrimStart(null);

                                int count = masterStr.IndexOf(separator);

                                if (count != -1)
                                {
                                    childEnum.Property.Value.SetValue(masterStr.Substring(0, count));
                                    if (count + 2 < masterStr.Length)
                                    {
                                        masterStr = masterStr.Substring(count + 2); // advance after the separator and the leading space
                                    }
                                }
                                else
                                {
                                    childEnum.Property.Value.SetValue(masterStr);
                                    break;
                                }

                                childEnum.MoveNext();
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #2
0
        public override bool ValidateValue(object value, out PropertyEnumerator invalidPropertyEnum)
        {
            invalidPropertyEnum = Grid.RightBound;

            // Validate the underlying value
            if (Validator != null)
            {
                if (Validator.Check(value, false) == false)
                {
                    invalidPropertyEnum = mOwnerEnumerator;
                    return(false);
                }
            }

            // Validate children if any
            if (mOwnerEnumerator != null)
            {
                PropertyEnumerator childEnum = mOwnerEnumerator.Children;
                while (childEnum != childEnum.RightBound)
                {
                    if (childEnum.Property.Value != null)
                    {
                        PropertyValidatorBase validator = childEnum.Property.Value.Validator;
                        if (validator != null)
                        {
                            object childValue = childEnum.Property.Value.PropertyDescriptor.GetValue(value);
                            if (validator.Check(childValue, false) == false)
                            {
                                invalidPropertyEnum = childEnum;
                                return(false);
                            }
                        }
                    }

                    childEnum.MoveNext();
                }
            }

            // Validate parent if any
            if (mOwnerEnumerator != null)
            {
                PropertyEnumerator parentEnum = mOwnerEnumerator.Parent;
                if ((parentEnum.Property != null) && (parentEnum.Property.Value != null))
                {
                    bool valid = parentEnum.Property.Value.ValidateSelfValueFromModifiedChild(mOwnerEnumerator, value);
                    if (!valid)
                    {
                        invalidPropertyEnum = parentEnum;
                    }

                    return(valid);
                }
            }

            return(true);
        }
Example #3
0
        protected internal override bool ValidateSelfValueFromModifiedChild(PropertyEnumerator modifiedChildEnum, object value)
        {
            if (NoLinkWithChildren)
            {
                return(true);
            }

            if (Validator != null)
            {
                string             str       = "";
                PropertyEnumerator selfEnum  = modifiedChildEnum.Parent;
                PropertyEnumerator childEnum = selfEnum.Children;
                while (childEnum != childEnum.RightBound)
                {
                    if (childEnum.Equals(modifiedChildEnum))
                    {
                        if (value is string)
                        {
                            str += (value as string);
                        }
                        else
                        {
                            PropertyTypeDescriptorContext context = childEnum.Property.Value.GetTypeDescriptorContext(childEnum);
                            str += (string)TypeDescriptor.GetConverter(value).ConvertTo(context,
                                                                                        childEnum.Property.Value.CultureInfo, value, typeof(string));
                        }
                    }
                    else
                    {
                        str += childEnum.Property.Value.GetStringValue();
                    }
                    childEnum.MoveNext();

                    if (childEnum != childEnum.RightBound)
                    {
                        str += GroupedValueSeparator;
                        str += " ";
                    }
                }

                if (Validator.Check(str, false) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #4
0
        public void UpdateValueFromChildren(PropertyEnumerator propEnum)
        {
            string str = "";

            PropertyEnumerator childEnum = propEnum.Children;
            char separator = propEnum.Property.Value.GroupedValueSeparator;

            while (childEnum != childEnum.RightBound)
            {
                str += childEnum.Property.Value.GetStringValue();
                childEnum.MoveNext();

                if (childEnum != childEnum.RightBound)
                {
                    str += separator;
                    str += " ";
                }
            }

            Value.SetValue(str);
        }
Example #5
0
        protected internal override void OnChildValueChanged(PropertyValue parentPropValue)
        {
            string str = "";

            PropertyEnumerator childEnum = mOwnerEnumerator.Children;
            char separator = mOwnerEnumerator.Property.Value.GroupedValueSeparator;

            while (childEnum != childEnum.RightBound)
            {
                str += childEnum.Property.Value.GetStringValue();
                childEnum.MoveNext();

                if (childEnum != childEnum.RightBound)
                {
                    str += separator;
                    str += " ";
                }
            }

            SetValue(str, ValueUpdateSource.FromChild);
        }
Example #6
0
        protected override bool ValidateValue(object value)
        {
            // Validate the underlying value
            if (Validator != null)
            {
                if (Validator.Check(value, false) == false)
                {
                    return(false);
                }
            }

            if (mOwnerEnumerator == null)
            {
                return(true);
            }

            if ((NoLinkWithChildren == false) && !TypeConverter.GetPropertiesSupported())
            {
                // Validate children if any
                PropertyEnumerator childEnum = mOwnerEnumerator.Children;
                if (childEnum.Count > 0)
                {
                    string masterStr = (value as string);

                    char separator = mOwnerEnumerator.Property.Value.GroupedValueSeparator;
                    while (childEnum != childEnum.RightBound)
                    {
                        PropertyValidatorBase validator = childEnum.Property.Value.Validator;

                        masterStr.TrimStart(null);

                        int count = masterStr.IndexOf(separator);

                        if (count != -1)
                        {
                            if ((validator != null) && (validator.Check(masterStr.Substring(0, count), false) == false))
                            {
                                return(false);
                            }

                            if (count + 2 < masterStr.Length)
                            {
                                masterStr = masterStr.Substring(count + 2); // advance after the separator and the leading space
                            }
                            childEnum.MoveNext();
                        }
                        else
                        {
                            if ((validator != null) && (validator.Check(masterStr, false) == false))
                            {
                                return(false);
                            }

                            break;
                        }
                    }
                }
            }

            // Validate parent if any
            PropertyEnumerator parentEnum = mOwnerEnumerator.Parent;

            if ((parentEnum.Property != null) && (parentEnum.Property.Value != null) &&
                (parentEnum.Property.Value.NoLinkWithChildren == false))
            {
                string             str       = "";
                PropertyEnumerator childEnum = parentEnum.Children;
                char separator = parentEnum.Property.Value.GroupedValueSeparator;
                while (childEnum != childEnum.RightBound)
                {
                    if (childEnum.Property.Value == this)
                    {
                        str += (value as string);
                    }
                    else
                    {
                        str += childEnum.Property.Value.GetStringValue();
                    }
                    childEnum.MoveNext();

                    if (childEnum != childEnum.RightBound)
                    {
                        str += separator;
                        str += " ";
                    }
                }

                PropertyValidatorBase validator = parentEnum.Property.Value.Validator;
                if ((validator != null) && (validator.Check(str, false) == false))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #7
0
        protected override bool SetValueInternal(object value, ValueUpdateSource updateSource)
        {
            bool result = true;

            // If the user tries to set the value as a string
            if ((value != null) && (value.GetType() == typeof(string)))
            {
                if (UnderlyingType == typeof(string))
                {
                    try
                    {
                        // We set the value directly to the underlying data (to its C# Field or Property)
                        if (_memberInfo.MemberType == MemberTypes.Property)
                        {
                            ((PropertyInfo)_memberInfo).GetSetMethod(true).Invoke(_targetInstance, new object[] { value });
                        }
                        else
                        {
                            ((FieldInfo)_memberInfo).SetValue(_targetInstance, value);
                        }
                    }
                    catch (ArgumentException)
                    {
                        result = false;
                    }
                }
                else
                {
                    try
                    {
                        string newString = GetActualString(value as string);
                        if (newString != null)
                        {
                            if (_memberInfo.MemberType == MemberTypes.Property)
                            {
                                ((PropertyInfo)_memberInfo).GetSetMethod(true).Invoke(_targetInstance, new object[] {
                                    TypeConverter.ConvertFromString(GetTypeDescriptorContext(OwnerEnumerator),
                                                                    CultureInfo, newString)
                                });
                            }
                            else
                            {
                                ((FieldInfo)_memberInfo).SetValue(_targetInstance, TypeConverter.ConvertFromString(
                                                                      GetTypeDescriptorContext(OwnerEnumerator), CultureInfo, newString));
                            }
                        }
                        else
                        {
                            if (_memberInfo.MemberType == MemberTypes.Property)
                            {
                                ((PropertyInfo)_memberInfo).GetSetMethod(true).Invoke(_targetInstance, new object[] {
                                    TypeConverter.ConvertFromString(GetTypeDescriptorContext(OwnerEnumerator),
                                                                    CultureInfo, value as string)
                                });
                            }
                            else
                            {
                                ((FieldInfo)_memberInfo).SetValue(_targetInstance, TypeConverter.ConvertFromString(
                                                                      GetTypeDescriptorContext(OwnerEnumerator), CultureInfo, value as string));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        result = false;
                    }
                }
            }

            // Else if the user doesn't try to set the value as a string
            else
            {
                try
                {
                    // We set the value directly to the underlying data (to its C# Field or Property)
                    if (_memberInfo.MemberType == MemberTypes.Property)
                    {
                        ((PropertyInfo)_memberInfo).GetSetMethod(true).Invoke(_targetInstance, new object[] { value });
                    }
                    else
                    {
                        ((FieldInfo)_memberInfo).SetValue(_targetInstance, value);
                    }
                }
                catch (ArgumentException)
                {
                    result = false;
                }
            }

            if (updateSource != ValueUpdateSource.FromChild)
            {
                if (mOwnerEnumerator != null)   // mOwnerEnumerator could be null for the boolean of Property._enabledVariable
                {
                    PropertyEnumerator childEnum = mOwnerEnumerator.Children;
                    if (childEnum.Count > 0)
                    {
                        string masterStr = mOwnerEnumerator.Property.Value.GetStringValue();

                        char separator = mOwnerEnumerator.Property.Value.GroupedValueSeparator;
                        while (childEnum != childEnum.RightBound)
                        {
                            masterStr.TrimStart(null);

                            int count = masterStr.IndexOf(separator);

                            if (count != -1)
                            {
                                childEnum.Property.Value.SetValue(masterStr.Substring(0, count));
                                if (count + 2 < masterStr.Length)
                                {
                                    masterStr = masterStr.Substring(count + 2); // advance after the separator and the leading space
                                }
                            }
                            else
                            {
                                childEnum.Property.Value.SetValue(masterStr);
                                break;
                            }

                            childEnum.MoveNext();
                        }
                    }
                }
            }

            return(result);
        }
Example #8
0
        public override bool ValidateValue(object value, out PropertyEnumerator invalidPropertyEnum)
        {
            invalidPropertyEnum = Grid.RightBound;

            // Validate the underlying value
            if (Validator != null)
            {
                if (Validator.Check(value, false) == false)
                {
                    invalidPropertyEnum = OwnerEnumerator;
                    return(false);
                }
            }

            if (mOwnerEnumerator == null)
            {
                return(true);
            }

            if ((NoLinkWithChildren == false) && !TypeConverter.GetPropertiesSupported())
            {
                // Validate children if any
                PropertyEnumerator childEnum = mOwnerEnumerator.Children;
                if (childEnum.Count > 0)
                {
                    string masterStr = (value as string);

                    char separator = mOwnerEnumerator.Property.Value.GroupedValueSeparator;
                    while (childEnum != childEnum.RightBound)
                    {
                        PropertyValidatorBase validator = childEnum.Property.Value.Validator;

                        masterStr.TrimStart(null);

                        int count = masterStr.IndexOf(separator);

                        if (count != -1)
                        {
                            if (validator != null)
                            {
                                object valueToCheck = childEnum.Property.Value.TypeConverter.ConvertFrom(
                                    GetTypeDescriptorContext(childEnum),
                                    childEnum.Property.Value.CultureInfo,
                                    masterStr.Substring(0, count));

                                if (validator.Check(valueToCheck, false) == false)
                                {
                                    invalidPropertyEnum = childEnum;
                                    return(false);
                                }
                            }

                            if (count + 2 < masterStr.Length)
                            {
                                masterStr = masterStr.Substring(count + 2); // advance after the separator and the leading space
                            }
                            childEnum.MoveNext();
                        }
                        else
                        {
                            if (validator != null)
                            {
                                object valueToCheck = childEnum.Property.Value.TypeConverter.ConvertFrom(
                                    GetTypeDescriptorContext(childEnum),
                                    childEnum.Property.Value.CultureInfo,
                                    masterStr);

                                if (validator.Check(valueToCheck, false) == false)
                                {
                                    invalidPropertyEnum = childEnum;
                                    return(false);
                                }
                            }

                            break;
                        }
                    }
                }
            }

            // Validate parent if any
            if (mOwnerEnumerator != null)
            {
                PropertyEnumerator parentEnum = mOwnerEnumerator.Parent;
                if ((parentEnum.Property != null) && (parentEnum.Property.Value != null))
                {
                    bool valid = parentEnum.Property.Value.ValidateSelfValueFromModifiedChild(mOwnerEnumerator, value);
                    if (!valid)
                    {
                        invalidPropertyEnum = parentEnum;
                    }
                    return(valid);
                }
            }

/*
 *          PropertyEnumerator parentEnum = mOwnerEnumerator.Parent;
 *          if ((parentEnum.Property != null) && (parentEnum.Property.Value != null) &&
 *              (parentEnum.Property.Value.NoLinkWithChildren == false))
 *          {
 *              string str = "";
 *              PropertyEnumerator childEnum = parentEnum.Children;
 *              char separator = parentEnum.Property.Value.GroupedValueSeparator;
 *              while (childEnum != childEnum.RightBound)
 *              {
 *                  if (childEnum.Property.Value == this)
 *                      str += (value as string);
 *                  else
 *                      str += childEnum.Property.Value.GetStringValue();
 *                  childEnum.MoveNext();
 *
 *                  if (childEnum != childEnum.RightBound)
 *                  {
 *                      str += separator;
 *                      str += " ";
 *                  }
 *              }
 *
 *              PropertyValidatorBase validator = parentEnum.Property.Value.Validator;
 *              if ((validator != null) && (validator.Check(str, false) == false))
 *                  return false;
 *          }*/

            return(true);
        }
Example #9
0
        public virtual void RestorePropertiesStates(PropertyEnumerator propEnum, object propertiesStates)
        {
            PropertyEnumerator firstDisplayedPropertyEnum = null;
            int selectedPropertyVisibleIndex = (propertiesStates as PropertiesStates)._selectedPropertyVisibleIndex;
            
            while (propEnum != propEnum.RightBound)
            {
                int hashcode = GetPropertyHashCode(propEnum);

                if (hashcode == (propertiesStates as PropertiesStates)._firstDisplayedPropertyHashcode)
                    firstDisplayedPropertyEnum = (PropertyEnumerator)propEnum.Clone();

                object objState = (propertiesStates as PropertiesStates)._states[hashcode];
                if (objState != null)
                {
                    PropertiesStates.PropertyState state = (PropertiesStates.PropertyState)objState;
                    ExpandProperty(propEnum, state.expanded);
                    if (state.selected)
                    {
                        SelectProperty(propEnum);

                        if (selectedPropertyVisibleIndex != -1)
                        {
                            // The selected property was visible so we will ensure that it is displaye at
                            // the exact same row in the grid

                            int currentIndex = GetPropertyVisibleIndex(propEnum);
                            if (currentIndex == -1)
                            {
                                EnsureVisible(propEnum);
                                currentIndex = GetPropertyVisibleIndex(propEnum);
                            }

                            while (currentIndex > selectedPropertyVisibleIndex)
                            {
                                Win32Calls.SendMessage(Handle, Win32Calls.WM_VSCROLL, Win32Calls.MakeLong(Win32Calls.SB_LINEDOWN, 0), 0);
                                currentIndex--;
                            }
                            while (currentIndex < selectedPropertyVisibleIndex)
                            {
                                Win32Calls.SendMessage(Handle, Win32Calls.WM_VSCROLL, Win32Calls.MakeLong(Win32Calls.SB_LINEUP, 0), 0);
                                currentIndex++;
                            }
                        }
                    }
                }

                propEnum.MoveNext();
            }

            if ((selectedPropertyVisibleIndex == -1) && (firstDisplayedPropertyEnum != null))
            {
                // The selected property was not visible so we will rely on the first property that
                // was displayed in the grid

                _firstDisplayedLine = (propertiesStates as PropertiesStates)._firstDisplayedLine;
                FirstDisplayedProperty = firstDisplayedPropertyEnum.GetVisibleDeepEnumerator();
            }
        }
Example #10
0
        public object SavePropertiesStates(PropertyEnumerator propEnum)
        {
            PropertiesStates _propertiesStates = new PropertiesStates();

            while (propEnum != propEnum.RightBound)
            {
                int hashcode = GetPropertyHashCode(propEnum);

                if (propEnum == FirstDisplayedProperty)
                {
                    _propertiesStates._firstDisplayedPropertyHashcode = hashcode;
                    _propertiesStates._firstDisplayedLine = _firstDisplayedLine;
                }

                int index = 0;
                if (propEnum.Property.Selected)
                    _propertiesStates._selectedPropertyVisibleIndex = GetPropertyVisibleIndex(propEnum);

                PropertiesStates.PropertyState state = new PropertiesStates.PropertyState(
                    propEnum.Property.Expanded && (propEnum.Children.Count > 0),
                    propEnum.Property.Selected, index);

                _propertiesStates._states[hashcode] = state;

                propEnum.MoveNext();
            }

            return _propertiesStates;
        }