/// <summary>
        /// Gets the AccessibilityObject from a PropertyGrid.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The AccessibilityObject, or null if invalid or not of the correct type.</returns>
        static object TryGetPropertyGridAccessibleObject(ITypeDescriptorContext context)
        {
            const BindingFlags flags =
                BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Instance;

            if (context == null)
            {
                return(null);
            }

            try
            {
                // Check for the PropertyDescriptorGridEntry type
                if (context.GetType().FullName == "System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry")
                {
                    // Get the AccessibileObject from the AcccessibilityObject property
                    var propAccessibilityObject = context.GetType().GetProperty("AccessibilityObject", flags);
                    if (propAccessibilityObject == null)
                    {
                        return(null);
                    }

                    var accessibleObject = propAccessibilityObject.GetValue(context, null);
                    return(accessibleObject);
                }
            }
            catch (InvalidCastException)
            {
                return(null);
            }
            catch (TargetException)
            {
                return(null);
            }
            catch (TargetInvocationException)
            {
                return(null);
            }
            catch (ArgumentNullException)
            {
                return(null);
            }
            catch (ArgumentException)
            {
                return(null);
            }

            return(null);
        }
Beispiel #2
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            LinksNode node = value as LinksNode;

            /*context should be of type System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry
             * OwnerGrid is not a public property, we get it through reflection
             * A reference to the parent form is needed to add the ObjList to the ListEditingStack*/
            Type t = context.GetType();

            if (!(t.GetProperty("OwnerGrid").GetValue(context, null) is PropertyGrid targetGrid))
            {
                throw new Exception("context is not of the expected type");
            }
            if (!(targetGrid.ParentForm is IEditorFormContext TargetForm))
            {
                throw new Exception("context is not of the expected type");
            }
            if (node != null)
            {
                using (var form = new EditorFroms.LinksEditor(node, TargetForm))
                {
                    form.ShowDialog();
                }
            }
            return(node);
        }
Beispiel #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
                                           object value)
        {
            try
            {
                if (context == null)
                {
                    try
                    {
                        return(SdkIncompatibilityWarning.FromString((string)value));
                    }
                    catch
                    {
                        // Continue with the other method if parsing json failed.
                    }
                }

                var type = context.GetType().Assembly.GetTypes().First(
                    t => t.FullName == "System.Windows.Forms.PropertyGridInternal.GridEntry");
                var property =
                    type.GetProperty("PropertyValue", BindingFlags.Instance | BindingFlags.Public);
                var sdkWarningValue = (SdkIncompatibilityWarning)property.GetValue(context);

                sdkWarningValue.ShowOption = (ShowOption)base.ConvertFrom(context, culture, value);
                return(sdkWarningValue);
            }
            catch (Exception e)
            {
                Trace.WriteLine($"Could not convert value '{value}' " +
                                $"to type '{nameof(SdkIncompatibilityWarning)}'. " +
                                $"Exception: '{e.Message}'. Stack trace: '{e.StackTrace}'.");
            }

            return(new SdkIncompatibilityWarning());
        }
Beispiel #4
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (value is ICloneBySerialization)
     {
         ICloneBySerialization v = value as ICloneBySerialization;
         object c = v.CloneBySerialization();
         KzPropertiesGridDialog f  = new KzPropertiesGridDialog(c);
         PropertyInfo           pi = context.GetType().GetProperty("PropertyLabel");
         if (pi != null)
         {
             f.Text = pi.GetValue(context, null) as string;
         }
         if (f.ShowDialog() == DialogResult.OK)
         {
             return(f.Settings);
         }
         else
         {
             return(value);
         }
     }
     else
     {
         MessageBox.Show("Type does not derive from KzL.Drawing.ICloneBySerialization.");
         return(value);
     }
 }
        //! @endcond
        #endregion

        private static Control GetHost(ITypeDescriptorContext context)
        {
            //Control host = ((System.Windows.Forms.PropertyGridInternal.GridEntry)context).DesignerHost.RootComponent as Control;
            var pi = context?.GetType().GetProperty("DesignerHost", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var dh = pi?.GetValue(context) as IDesignerHost;

            return(dh?.RootComponent as Control);
        }
            public VirtualObjectProperty(ITypeDescriptorContext context, object baseObject, PropertyDescriptor baseProperty) : base(baseProperty)
            {
                this.baseObject   = baseObject;
                this.baseProperty = baseProperty;

                PropertyInfo propInfo = context.GetType().GetProperty("OwnerGrid");

                grid = propInfo.GetValue(context) as PropertyGrid;
            }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var property = context.GetType().GetProperty("Expanded");

            if (property != null)
            {
                property.SetValue(context, property.GetValue(context, null).Equals(false), null);
            }

            return(base.EditValue(context, provider, value));
        }
Beispiel #8
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     try
     {
         return(base.ConvertFrom(context, culture, value));
     }
     catch (Exception e)
     {
         PropertyInfo pi = context.GetType().GetProperty("Value");
         var          v  = (double)pi.GetValue(context);
         return(base.ConvertFrom(context, culture, v.ToString()));
     }
 }
Beispiel #9
0
        public static PropertyGrid GetPropertyGrid(ITypeDescriptorContext context)
        {
            if (context == null)
            {
                return((PropertyGrid)null);
            }
            PropertyInfo property     = context.GetType().GetProperty("OwnerGrid", BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);
            PropertyGrid propertyGrid = (PropertyGrid)null;

            if (property != (PropertyInfo)null)
            {
                propertyGrid = property.GetValue((object)context, (object[])null) as PropertyGrid;
            }
            return(propertyGrid);
        }
Beispiel #10
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            PropertyGrid grid = context.GetType().InvokeMember(
                "OwnerGrid",
                BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public,
                null,
                context,
                null) as PropertyGrid;

            List <string> vCol = new List <string>();

            try
            {
                if (grid != null)
                {
                    grid.Cursor = Cursors.WaitCursor;
                }

                dynamic reader = context.Instance;
                if (reader != null)
                {
                    if (!string.IsNullOrEmpty(reader.APIKey))
                    {
                        var entities = Cache.GetCacheItem((string)string.Format("MailChimp.MailChimpListTypeConverter.Lists.{0}", reader.APIKey), () => reader.GetMailChimpLists());

                        foreach (var e in entities.Values)
                        {
                            vCol.Add(e);
                        }

                        vCol.Sort();
                    }
                }
            }
            catch (ArgumentException)
            {
            }
            finally
            {
                if (grid != null)
                {
                    grid.Cursor = Cursors.Default;
                }
            }

            return(new StandardValuesCollection(vCol));
        }
Beispiel #11
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
                                           object value)
        {
            if (value is string)
            {
                PropertyInfo pi = context.GetType().GetProperty("PropertyValue");
                if (pi != null)
                {
                    object obj = pi.GetValue(context, null);
                    return(obj);
                }
            }

            object o = base.ConvertFrom(context, culture, value);

            return(o);
        }
        /// <summary>
        ///     Convert a string like "Button.Click" into the corresponding RoutedEvent
        /// </summary>
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
                                           CultureInfo cultureInfo,
                                           object source)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (s_ServiceProviderContextType == null)
            {
                // get typeof(MS.Internal.Xaml.ServiceProviderContext) via reflection
                Assembly a = typeof(IRootObjectProvider).Assembly;
                s_ServiceProviderContextType = a.GetType("MS.Internal.Xaml.ServiceProviderContext");
            }
            if (typeDescriptorContext.GetType() != s_ServiceProviderContextType)
            {
                // if the caller is not the XAML parser, don't answer.   This avoids
                // returning an arbitrary delegate to a (possibly malicious) caller.
                // See Dev11 629384.
                throw new ArgumentException(SR.Get(SRID.TextRange_InvalidParameterValue), "typeDescriptorContext");
            }
            IRootObjectProvider rootProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

            if (rootProvider != null && source is String)
            {
                IProvideValueTarget ipvt = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (ipvt != null)
                {
                    EventSetter setter = ipvt.TargetObject as EventSetter;
                    string      handlerName;
                    if (setter != null && (handlerName = source as string) != null)
                    {
                        handlerName = handlerName.Trim();
                        return(Delegate.CreateDelegate(setter.Event.HandlerType, rootProvider.RootObject, handlerName));
                    }
                }
            }

            throw GetConvertFromException(source);
        }
        /// <summary>
        ///     Convert a string like "Button.Click" into the corresponding RoutedEvent
        /// </summary>
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
                                           CultureInfo cultureInfo,
                                           object source)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (s_ServiceProviderContextType == null)
            {
                // get typeof(MS.Internal.Xaml.ServiceProviderContext) via reflection
                Assembly a = typeof(IRootObjectProvider).Assembly;
                s_ServiceProviderContextType = a.GetType("MS.Internal.Xaml.ServiceProviderContext");
            }
            if (typeDescriptorContext.GetType() != s_ServiceProviderContextType)
            {
                // if the caller is not the XAML parser, don't answer.   This avoids
                // returning an arbitrary delegate to a (possibly malicious) caller.
                // See Dev11 629384.
                throw new ArgumentException(SR.Get(SRID.TextRange_InvalidParameterValue), "typeDescriptorContext");
            }
            IRootObjectProvider rootProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
            if (rootProvider != null && source is String)
            {
                IProvideValueTarget ipvt = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (ipvt != null)
                {
                    EventSetter setter = ipvt.TargetObject as EventSetter;
                    string handlerName;
                    if(setter != null && (handlerName = source as string) != null)
                    {
                        handlerName = handlerName.Trim();
                        return Delegate.CreateDelegate(setter.Event.HandlerType, rootProvider.RootObject, handlerName);
                    }
                }
            }

            throw GetConvertFromException(source);
        }
Beispiel #14
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     string propertyGridName;
     object obj2 = context.GetType().GetProperty("OwnerGrid").GetValue(context, null);
     if ((obj2 != null) && (obj2 is PropertyGrid))
     {
         propertyGridName = ((PropertyGrid) obj2).Text;
     }
     else
     {
         return value;
     }
     string propertyName = context.PropertyDescriptor.Category;
     string categoryName = context.PropertyDescriptor.DisplayName;
     this.wfes = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
     string key = PropertyComboBox.getComboBoxID(propertyGridName, propertyName, categoryName);
     if ((this.wfes != null) && PropertyComboBox.s_htLists.ContainsKey(key))
     {
         propertyList pi = (propertyList) PropertyComboBox.s_htLists[key];
         if (pi == null)
         {
             return value;
         }
         this.fillListBox(pi, value);
         this.lb.Sorted = pi.isAutoSort;
         this.lb.BorderStyle = BorderStyle.FixedSingle;
         this.lb.DoubleClick += new EventHandler(this.lb_DoubleClick);
         this.lb.Click += new EventHandler(this.lb_Click);
         this.wfes.DropDownControl(this.lb);
         this.setSelectedItem(pi, key);
         if (this.lb.SelectedItem != null)
         {
             value = this.lb.SelectedItem;
         }
     }
     return value;
 }
Beispiel #15
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var grid = context.GetType().InvokeMember(
                "OwnerGrid",
                BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public,
                null,
                context,
                null) as PropertyGrid;

            var vCol = new List <string>();

            try
            {
                if (grid != null)
                {
                    grid.Cursor = Cursors.WaitCursor;
                }

                dynamic reader = context.Instance;
                if (reader != null)
                {
                    vCol.AddRange(reader.GetObjectNames());
                }
            }
            catch (ArgumentException)
            {
            }
            finally
            {
                if (grid != null)
                {
                    grid.Cursor = Cursors.Default;
                }
            }

            return(new StandardValuesCollection(vCol));
        }
        /// <summary>Converts the specified string to a new <see cref="T:System.Delegate" /> for the event handler.</summary>
        /// <param name="typeDescriptorContext">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
        /// <param name="cultureInfo">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture. </param>
        /// <param name="source">The source string to convert.</param>
        /// <returns>A new <see cref="T:System.Delegate" /> that represents the referenced event handler.</returns>
        /// <exception cref="T:System.NotSupportedException">The necessary services are not available.-or-Could not perform the specific conversion.</exception>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="typeDescriptorContext" /> or <paramref name="source" /> are <see langword="null" />.</exception>
        // Token: 0x06001D03 RID: 7427 RVA: 0x00087740 File Offset: 0x00085940
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (EventSetterHandlerConverter.s_ServiceProviderContextType == null)
            {
                Assembly assembly = typeof(IRootObjectProvider).Assembly;
                EventSetterHandlerConverter.s_ServiceProviderContextType = assembly.GetType("MS.Internal.Xaml.ServiceProviderContext");
            }
            if (typeDescriptorContext.GetType() != EventSetterHandlerConverter.s_ServiceProviderContextType)
            {
                throw new ArgumentException(SR.Get("TextRange_InvalidParameterValue"), "typeDescriptorContext");
            }
            IRootObjectProvider rootObjectProvider = typeDescriptorContext.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

            if (rootObjectProvider != null && source is string)
            {
                IProvideValueTarget provideValueTarget = typeDescriptorContext.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
                if (provideValueTarget != null)
                {
                    EventSetter eventSetter = provideValueTarget.TargetObject as EventSetter;
                    string      text;
                    if (eventSetter != null && (text = (source as string)) != null)
                    {
                        text = text.Trim();
                        return(Delegate.CreateDelegate(eventSetter.Event.HandlerType, rootObjectProvider.RootObject, text));
                    }
                }
            }
            throw base.GetConvertFromException(source);
        }
        /// <summary>
        /// Gets the AccessibilityObject from a PropertyGrid.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>The AccessibilityObject, or null if invalid or not of the correct type.</returns>
        static object TryGetPropertyGridAccessibleObject(ITypeDescriptorContext context)
        {
            const BindingFlags flags =
                BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Instance;

            if (context == null)
                return null;

            try
            {
                // Check for the PropertyDescriptorGridEntry type
                if (context.GetType().FullName == "System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry")
                {
                    // Get the AccessibileObject from the AcccessibilityObject property
                    var propAccessibilityObject = context.GetType().GetProperty("AccessibilityObject", flags);
                    if (propAccessibilityObject == null)
                        return null;

                    var accessibleObject = propAccessibilityObject.GetValue(context, null);
                    return accessibleObject;
                }
            }
            catch (InvalidCastException)
            {
                return null;
            }
            catch (TargetException)
            {
                return null;
            }
            catch (TargetInvocationException)
            {
                return null;
            }
            catch (ArgumentNullException)
            {
                return null;
            }
            catch (ArgumentException)
            {
                return null;
            }

            return null;
        }
Beispiel #18
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            var c = s_typeDescriptorContentType.GetTypeInfo().IsAssignableFrom(context?.GetType().GetTypeInfo()) ? context : null;

            return(_convertTo?.Invoke(_typeConverter, new object[] { c, culture, value, destinationType }));
        }
Beispiel #19
0
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            var c = s_typeDescriptorContentType.GetTypeInfo().IsAssignableFrom(context?.GetType().GetTypeInfo()) ? context : null;

            return((bool)(_canConvertTo?.Invoke(_typeConverter, new object[] { c, destinationType }) ?? false));
        }
 public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     PropertyInfo propInfo = context.GetType().GetProperty("OwnerGrid");
     PropertyGrid propGrid = propInfo.GetValue(context, null) as PropertyGrid;
     snConfig snConfig = propGrid.Tag as snConfig;
     List<String> retVal = new List<String>();
     foreach (object action in snConfig.devices.Items)
     {
         PropertyInfo namePropertyInfo = action.GetType().GetProperty("name");
         String name = namePropertyInfo.GetValue(action, null) as String;
         retVal.Add(name);
     }
     return new StandardValuesCollection(retVal);
 }
Beispiel #21
0
        public override object EditValue(ITypeDescriptorContext context,
            IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService wfes = (IWindowsFormsEditorService)provider.GetService(
                typeof(IWindowsFormsEditorService));

            if (wfes != null)
            {
                SliderForm sliderForm = new SliderForm();
                // type+category+displayedName
                String key = context.PropertyDescriptor.ComponentType.Name + context.PropertyDescriptor.Category + context.PropertyDescriptor.DisplayName;
                bool maxOK = false, minOK = false;
                if (maximumValue.ContainsKey(key))
                {
                    sliderForm.trackBar.Maximum = maximumValue[key];
                    maxOK = true;
                }
                if (minimumValue.ContainsKey(key))
                {
                    sliderForm.trackBar.Minimum = minimumValue[key];
                    minOK = true;
                }

                if (!minOK || !maxOK)
                {
                    CustomPropertyGrid parentGrid;
                    PropertyInfo piOwnerGrid = context.GetType().GetProperty("OwnerGrid");
                    Object grid = piOwnerGrid.GetValue(context, null);
                    if ((grid != null) && (grid is CustomPropertyGrid))
                    {
                        parentGrid = (CustomPropertyGrid)grid;
                    }
                    else
                    {
                        parentGrid = null;
                    }
                    if (parentGrid != null)
                    {
                        // try and get the parameter info to check for constraints - to set min and max
                        IXPathNavigable iNav = parentGrid.Controller.GetParametersForComponent(parentGrid.SelectedID);
                        XPathNavigator nav = iNav.CreateNavigator();
                        XPathNodeIterator constraints = nav.Select("ComponentParameters/Parameter[@category='" + context.PropertyDescriptor.Category +
                            "']/Parameter[@displayedName='" + context.PropertyDescriptor.DisplayName + "']/Constraints/Constraint");

                        foreach (XPathNavigator constraint in constraints)
                        {
                            String constraintName = constraint.GetAttribute(ConfigFileConstants.constraintName, "");
                            String constraintValue = constraint.GetAttribute(ConfigFileConstants.constraintValue, "");
                            Int32 parse;
                            if (constraintName.Equals(ConfigFileConstants.maxConstraint))
                            {
                                parse = Int32.Parse(constraintValue);
                                sliderForm.trackBar.Maximum = parse;
                                maximumValue.Add(key, parse); // save so we don't have to reprocess this every time
                            }
                            else if (constraintName.Equals(ConfigFileConstants.minConstraint))
                            {
                                parse = Int32.Parse(constraintValue);
                                sliderForm.trackBar.Minimum = parse;
                                minimumValue.Add(key, parse);
                            }
                        }
                    }
                }

                sliderForm.trackBar.Value = (int)value;
                sliderForm.wfes = wfes;

                wfes.DropDownControl(sliderForm);

                value = sliderForm.trackBar.Value;
            }
            return value;
        }