public AxPerPropertyBrowsingEnum(AxPropertyDescriptor targetObject, AxHost owner, OleStrCAMarshaler names, Int32CAMarshaler values, bool allowUnknowns) : base(Array.Empty <string>(), Array.Empty <object>(), allowUnknowns)
 {
     target          = targetObject;
     nameMarshaller  = names;
     valueMarshaller = values;
     this.owner      = owner;
     arraysFetched   = false;
 }
 public AxPerPropertyBrowsingEnum(
     AxPropertyDescriptor targetObject,
     AxHost owner,
     string[] names,
     uint[] cookies)
 {
     _target        = targetObject;
     _names         = names;
     _cookies       = cookies;
     _owner         = owner;
     _arraysFetched = false;
 }
Exemplo n.º 3
0
            HRESULT IPropertyNotifySink.OnChanged(DispatchID dispid)
            {
                // Some controls fire OnChanged() notifications when getting values of some properties.
                // To prevent this kind of recursion, we check to see if we are already inside a OnChanged() call.
                if (host.NoComponentChangeEvents != 0)
                {
                    return(HRESULT.S_OK);
                }

                host.NoComponentChangeEvents++;
                try
                {
                    AxPropertyDescriptor prop = null;

                    Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in OnChanged");

                    if (dispid != DispatchID.UNKNOWN)
                    {
                        prop = host.GetPropertyDescriptorFromDispid(dispid);
                        if (prop != null)
                        {
                            prop.OnValueChanged(host);
                            if (!prop.SettingValue)
                            {
                                prop.UpdateTypeConverterAndTypeEditor(true);
                            }
                        }
                    }
                    else
                    {
                        // update them all for DISPID_UNKNOWN.
                        PropertyDescriptorCollection props = ((ICustomTypeDescriptor)host).GetProperties();
                        foreach (PropertyDescriptor p in props)
                        {
                            prop = p as AxPropertyDescriptor;
                            if (prop != null && !prop.SettingValue)
                            {
                                prop.UpdateTypeConverterAndTypeEditor(true);
                            }
                        }
                    }

                    ISite site = host.Site;
                    if (site != null)
                    {
                        IComponentChangeService changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));

                        if (changeService != null)
                        {
                            try
                            {
                                changeService.OnComponentChanging(host, prop);
                            }
                            catch (CheckoutException coEx)
                            {
                                if (coEx == CheckoutException.Canceled)
                                {
                                    return(HRESULT.S_OK);
                                }
                                throw;
                            }

                            // Now notify the change service that the change was successful.
                            //
                            changeService.OnComponentChanged(host, prop, null, (prop?.GetValue(host)));
                        }
                    }
                }
                catch (Exception t)
                {
                    Debug.Fail(t.ToString());
                    throw;
                }
                finally
                {
                    host.NoComponentChangeEvents--;
                }

                return(HRESULT.S_OK);
            }
Exemplo n.º 4
0
 public AxPropertyTypeEditor(AxPropertyDescriptor pd, Guid guid)
 {
     _propertyDescriptor = pd;
     _guid = guid;
 }
 private PropertyDescriptorCollection FillProperties(Attribute[] attributes)
 {
     if (this.RefreshAllProperties)
     {
         this.RefreshAllProperties = false;
         this.propsStash = null;
         this.attribsStash = null;
     }
     else if (this.propsStash != null)
     {
         if ((attributes == null) && (this.attribsStash == null))
         {
             return this.propsStash;
         }
         if (((attributes != null) && (this.attribsStash != null)) && (attributes.Length == this.attribsStash.Length))
         {
             bool flag = true;
             int num = 0;
             foreach (Attribute attribute in attributes)
             {
                 if (!attribute.Equals(this.attribsStash[num++]))
                 {
                     flag = false;
                     break;
                 }
             }
             if (flag)
             {
                 return this.propsStash;
             }
         }
     }
     ArrayList list = new ArrayList();
     if (this.properties == null)
     {
         this.properties = new Hashtable();
     }
     if (this.propertyInfos == null)
     {
         this.propertyInfos = new Hashtable();
         foreach (PropertyInfo info in base.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
         {
             this.propertyInfos.Add(info.Name, info);
         }
     }
     PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(this, null, true);
     if (descriptors != null)
     {
         for (int i = 0; i < descriptors.Count; i++)
         {
             if (descriptors[i].DesignTimeOnly)
             {
                 list.Add(descriptors[i]);
             }
             else
             {
                 string name = descriptors[i].Name;
                 PropertyDescriptor descriptor = null;
                 PropertyInfo info2 = (PropertyInfo) this.propertyInfos[name];
                 if ((info2 == null) || info2.CanRead)
                 {
                     if (!this.properties.ContainsKey(name))
                     {
                         if (info2 != null)
                         {
                             descriptor = new AxPropertyDescriptor(descriptors[i], this);
                             ((AxPropertyDescriptor) descriptor).UpdateAttributes();
                         }
                         else
                         {
                             descriptor = descriptors[i];
                         }
                         this.properties.Add(name, descriptor);
                         list.Add(descriptor);
                     }
                     else
                     {
                         PropertyDescriptor descriptor2 = (PropertyDescriptor) this.properties[name];
                         AxPropertyDescriptor descriptor3 = descriptor2 as AxPropertyDescriptor;
                         if (((info2 != null) || (descriptor3 == null)) && ((info2 == null) || (descriptor3 != null)))
                         {
                             if (descriptor3 != null)
                             {
                                 descriptor3.UpdateAttributes();
                             }
                             list.Add(descriptor2);
                         }
                     }
                 }
             }
         }
         if (attributes != null)
         {
             Attribute attribute2 = null;
             foreach (Attribute attribute3 in attributes)
             {
                 if (attribute3 is BrowsableAttribute)
                 {
                     attribute2 = attribute3;
                 }
             }
             if (attribute2 != null)
             {
                 ArrayList list2 = null;
                 foreach (PropertyDescriptor descriptor4 in list)
                 {
                     if (descriptor4 is AxPropertyDescriptor)
                     {
                         Attribute attribute4 = descriptor4.Attributes[typeof(BrowsableAttribute)];
                         if ((attribute4 != null) && !attribute4.Equals(attribute2))
                         {
                             if (list2 == null)
                             {
                                 list2 = new ArrayList();
                             }
                             list2.Add(descriptor4);
                         }
                     }
                 }
                 if (list2 != null)
                 {
                     foreach (object obj2 in list2)
                     {
                         list.Remove(obj2);
                     }
                 }
             }
         }
     }
     PropertyDescriptor[] array = new PropertyDescriptor[list.Count];
     list.CopyTo(array, 0);
     this.propsStash = new PropertyDescriptorCollection(array);
     this.attribsStash = attributes;
     return this.propsStash;
 }
Exemplo n.º 6
0
 public AxEnumConverter(AxPropertyDescriptor target, Com2Enum com2Enum)
     : base(com2Enum)
 {
     _target = target;
 }
Exemplo n.º 7
0
 public AxPerPropertyBrowsingEnum(AxPropertyDescriptor targetObject, AxHost owner, OleStrCAMarshaler names, Int32CAMarshaler values, bool allowUnknowns) : base(new string[0], new object[0], allowUnknowns) {
     this.target = targetObject;
     this.nameMarshaller = names;
     this.valueMarshaller = values;
     this.owner = owner;
     this.arraysFetched = false;
 }
Exemplo n.º 8
0
 public AxEnumConverter(AxPropertyDescriptor target, Com2Enum com2Enum) : base(com2Enum) {
     this.target = target;                                                                                                  
 }
Exemplo n.º 9
0
 public AxPropertyTypeEditor(AxPropertyDescriptor pd, Guid guid) {
     propDesc = pd;
     this.guid = guid;
 }
Exemplo n.º 10
0
        private PropertyDescriptorCollection FillProperties(Attribute[] attributes) {
            if (RefreshAllProperties) {
                RefreshAllProperties = false;
                propsStash = null;
                attribsStash = null;
            }
            else if (propsStash != null) {
                if (attributes == null && attribsStash == null) {
                    Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Returning stashed values for : " + "<null>");
                    return propsStash;
                }
                else if (attributes != null && attribsStash != null && attributes.Length == attribsStash.Length) {
                    bool attribsEqual = true;
                    int i = 0;
                    foreach(Attribute attrib in attributes) {
                        if (!attrib.Equals(attribsStash[i++])) {
                            attribsEqual = false;
                            break;
                        }
                    }

                    if (attribsEqual) {
                        Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Returning stashed values for : " + attributes.Length);
                        return propsStash;
                    }
                }
            }

            ArrayList retProps = new ArrayList();

            if (properties == null)
                properties = new Hashtable();

            if (propertyInfos == null) {
                propertyInfos = new Hashtable();

                PropertyInfo[] propInfos = this.GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);

                foreach(PropertyInfo propInfo in propInfos)
                    propertyInfos.Add(propInfo.Name, propInfo);
            }

            PropertyDescriptorCollection baseProps = TypeDescriptor.GetProperties(this, null, true);
            if (baseProps != null) {
                for (int i = 0; i < baseProps.Count; ++i) {
                    Debug.Assert(baseProps[i] != null, "Null base prop at location: " + i.ToString(CultureInfo.InvariantCulture));

                    if (baseProps[i].DesignTimeOnly) {
                        retProps.Add(baseProps[i]);
                        continue;
                    }

                    string propName = baseProps[i].Name;
                    PropertyDescriptor prop = null;
                    PropertyInfo propInfo = (PropertyInfo)propertyInfos[propName];

                    // We do not support "write-only" properties that some activex controls support.
                    if (propInfo != null && !propInfo.CanRead)
                        continue;

                    if (!properties.ContainsKey(propName)) {
                        if (propInfo != null) {
                            Debug.WriteLineIf(AxPropTraceSwitch.TraceVerbose, "Added AxPropertyDescriptor for: " + propName);
                            prop = new AxPropertyDescriptor(baseProps[i], this);
                            ((AxPropertyDescriptor)prop).UpdateAttributes();
                        }
                        else {
                            Debug.WriteLineIf(AxPropTraceSwitch.TraceVerbose, "Added PropertyDescriptor for: " + propName);
                            prop = baseProps[i];
                        }
                        properties.Add(propName, prop);
                        retProps.Add(prop);
                    }
                    else {
                        PropertyDescriptor propDesc = (PropertyDescriptor)properties[propName];
                        Debug.Assert(propDesc != null, "Cannot find cached entry for: " + propName);
                        AxPropertyDescriptor axPropDesc = propDesc as AxPropertyDescriptor;
                        if ((propInfo == null && axPropDesc != null) || (propInfo != null && axPropDesc == null)) {
                            Debug.Fail("Duplicate property with same name: " + propName);
                            Debug.WriteLineIf(AxPropTraceSwitch.TraceVerbose, "Duplicate property with same name: " + propName);
                        }
                        else {
                            if (axPropDesc != null) {
                                axPropDesc.UpdateAttributes();
                            }
                            retProps.Add(propDesc);
                        }
                    }
                }

                // Filter only the Browsable attribute, since that is the only
                // one we mess with.
                //
                if (attributes != null) {
                    Attribute browse = null;
                    foreach(Attribute attr in attributes) {
                        if (attr is BrowsableAttribute) {
                            browse = attr;
                        }
                    }

                    if (browse != null) {
                        ArrayList removeList = null;

                        foreach(PropertyDescriptor prop in retProps) {
                            if (prop is AxPropertyDescriptor) {
                                Attribute attr = prop.Attributes[typeof(BrowsableAttribute)];
                                if (attr != null && !attr.Equals(browse)) {
                                    if (removeList == null) {
                                        removeList = new ArrayList();
                                    }
                                    removeList.Add(prop);
                                }
                            }
                        }

                        if (removeList != null) {
                            foreach(object prop in removeList)
                                retProps.Remove(prop);
                        }
                    }
                }
            }

            PropertyDescriptor[] temp = new PropertyDescriptor[retProps.Count];
            retProps.CopyTo(temp, 0);
            
            // Update our stashed values.
            //
            Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "Updating stashed values for : " + ((attributes != null) ? attributes.Length.ToString(CultureInfo.InvariantCulture) : "<null>"));
            propsStash = new PropertyDescriptorCollection(temp);
            attribsStash = attributes;
            
            return propsStash;
        }
Exemplo n.º 11
0
 public AxPropertyTypeEditor(AxPropertyDescriptor pd, Guid guid)
 {
     propDesc  = pd;
     this.guid = guid;
 }