internal override void OnPropertyChanged(Ole32.DispatchID dispid)
 {
     if (dispid != Ole32.DispatchID.READYSTATE)
     {
         base.OnPropertyChanged(dispid);
     }
 }
Exemple #2
0
        internal unsafe object GetPropertyValue(object component, string propertyName, ref bool succeeded)
        {
            if (!(component is UnsafeNativeMethods.IDispatch))
            {
                return(null);
            }

            UnsafeNativeMethods.IDispatch iDispatch = (UnsafeNativeMethods.IDispatch)component;
            string[]         names  = new string[] { propertyName };
            Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
            Guid             g      = Guid.Empty;

            try
            {
                HRESULT hr = iDispatch.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                if (dispid == Ole32.DispatchID.UNKNOWN || !hr.Succeeded())
                {
                    return(null);
                }

                return(GetPropertyValue(component, dispid, ref succeeded));
            }
            catch
            {
                return(null);
            }
        }
Exemple #3
0
            private unsafe Guid GetPropertyPage(Ole32.DispatchID dispid)
            {
                try
                {
                    Oleaut32.IPerPropertyBrowsing ippb = _owner.GetPerPropertyBrowsing();
                    if (ippb is null)
                    {
                        return(Guid.Empty);
                    }

                    Guid rval = Guid.Empty;
                    if (ippb.MapPropertyToPage(dispid, &rval).Succeeded())
                    {
                        return(rval);
                    }
                }
                catch (COMException)
                {
                }
                catch (Exception t)
                {
                    Debug.Fail(t.ToString());
                }
                return(Guid.Empty);
            }
 internal AmbientProperty(string name, Ole32.DispatchID dispID)
 {
     Name   = name;
     DispID = dispID;
     _value = null;
     Empty  = true;
 }
Exemple #5
0
        // IPropertyNotifySink methods:
        HRESULT Ole32.IPropertyNotifySink.OnChanged(Ole32.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
            {
                OnPropertyChanged(dispid);
            }
            catch (Exception t)
            {
                Debug.Fail(t.ToString());
                throw;
            }
            finally
            {
                Host.NoComponentChangeEvents--;
            }

            return(HRESULT.S_OK);
        }
Exemple #6
0
        public unsafe object InvokeScript(string scriptName, object[] args)
        {
            object retVal     = null;
            var    dispParams = new Ole32.DISPPARAMS
            {
                rgvarg = IntPtr.Zero
            };

            try
            {
                if (NativeHtmlDocument2.GetScript() is UnsafeNativeMethods.IDispatch scriptObject)
                {
                    Guid             g      = Guid.Empty;
                    string[]         names  = new string[] { scriptName };
                    Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
                    HRESULT          hr     = scriptObject.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                    if (hr.Succeeded() && dispid != Ole32.DispatchID.UNKNOWN)
                    {
                        if (args != null)
                        {
                            // Reverse the arg order so that parms read naturally after IDispatch. (
                            Array.Reverse(args);
                        }
                        dispParams.rgvarg            = (args == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(args);
                        dispParams.cArgs             = (args == null) ? 0 : (uint)args.Length;
                        dispParams.rgdispidNamedArgs = IntPtr.Zero;
                        dispParams.cNamedArgs        = 0;

                        object[] retVals    = new object[1];
                        var      pExcepInfo = new Ole32.EXCEPINFO();

                        hr = scriptObject.Invoke(
                            dispid,
                            &g,
                            Kernel32.GetThreadLocale(),
                            Oleaut32.DISPATCH.METHOD,
                            &dispParams,
                            retVals,
                            &pExcepInfo,
                            null);
                        if (hr == HRESULT.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex) when(!ClientUtils.IsSecurityOrCriticalException(ex))
            {
            }
            finally
            {
                if (dispParams.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dispParams.rgvarg, args.Length);
                }
            }

            return(retVal);
        }
        public unsafe object InvokeMember(string methodName, params object[] parameter)
        {
            object retVal = null;

            NativeMethods.tagDISPPARAMS dp = new NativeMethods.tagDISPPARAMS
            {
                rgvarg = IntPtr.Zero
            };
            try
            {
                if (NativeHtmlElement is UnsafeNativeMethods.IDispatch scriptObject)
                {
                    Guid             g      = Guid.Empty;
                    string[]         names  = new string[] { methodName };
                    Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
                    HRESULT          hr     = scriptObject.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                    if (hr.Succeeded() && dispid != Ole32.DispatchID.UNKNOWN)
                    {
                        // Reverse the arg order below so that parms are read properly thru IDispatch. (
                        if (parameter != null)
                        {
                            // Reverse the parm order so that they read naturally after IDispatch. (
                            Array.Reverse(parameter);
                        }
                        dp.rgvarg            = (parameter == null) ? IntPtr.Zero : HtmlDocument.ArrayToVARIANTVector(parameter);
                        dp.cArgs             = (parameter == null) ? 0 : parameter.Length;
                        dp.rgdispidNamedArgs = IntPtr.Zero;
                        dp.cNamedArgs        = 0;

                        object[] retVals = new object[1];
                        hr = scriptObject.Invoke(
                            dispid,
                            ref g,
                            Kernel32.GetThreadLocale(),
                            NativeMethods.DISPATCH_METHOD,
                            dp,
                            retVals,
                            new NativeMethods.tagEXCEPINFO(),
                            null);
                        if (hr == HRESULT.S_OK)
                        {
                            retVal = retVals[0];
                        }
                    }
                }
            }
            catch (Exception ex) when(!ClientUtils.IsSecurityOrCriticalException(ex))
            {
            }
            finally
            {
                if (dp.rgvarg != IntPtr.Zero)
                {
                    HtmlDocument.FreeVARIANTVector(dp.rgvarg, parameter.Length);
                }
            }

            return(retVal);
        }
Exemple #8
0
        /// <summary>
        ///  Checks if the given dispid matches the dispid that the Object would like to specify
        ///  as its identification proeprty (Name, ID, etc).
        /// </summary>
        internal bool IsNameDispId(object obj, Ole32.DispatchID dispid)
        {
            if (obj == null || !obj.GetType().IsCOMObject)
            {
                return(false);
            }

            return(dispid == Com2TypeInfoProcessor.GetNameDispId((UnsafeNativeMethods.IDispatch)obj));
        }
        public unsafe object InvokeScript(string scriptName, object[] args)
        {
            try
            {
                if (NativeHtmlDocument2.GetScript() is Oleaut32.IDispatch scriptObject)
                {
                    Guid             g      = Guid.Empty;
                    string[]         names  = new string[] { scriptName };
                    Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
                    HRESULT          hr     = scriptObject.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &dispid);
                    if (!hr.Succeeded() || dispid == Ole32.DispatchID.UNKNOWN)
                    {
                        return(null);
                    }

                    if (args != null)
                    {
                        // Reverse the arg order so that they read naturally after IDispatch.
                        Array.Reverse(args);
                    }

                    using var vectorArgs = new Oleaut32.VARIANTVector(args);
                    fixed(Oleaut32.VARIANT *pVariants = vectorArgs.Variants)
                    {
                        var dispParams = new Oleaut32.DISPPARAMS();

                        dispParams.rgvarg            = pVariants;
                        dispParams.cArgs             = (uint)vectorArgs.Variants.Length;
                        dispParams.rgdispidNamedArgs = null;
                        dispParams.cNamedArgs        = 0;

                        var retVals   = new object[1];
                        var excepInfo = new Oleaut32.EXCEPINFO();

                        hr = scriptObject.Invoke(
                            dispid,
                            &g,
                            Kernel32.GetThreadLocale(),
                            Oleaut32.DISPATCH.METHOD,
                            &dispParams,
                            retVals,
                            &excepInfo,
                            null);
                        if (hr == HRESULT.S_OK)
                        {
                            return(retVals[0]);
                        }
                    }
                }
            }
            catch (Exception ex) when(!ClientUtils.IsCriticalException(ex))
            {
            }

            return(null);
        }
        private unsafe string GetCategoryFromObject(object obj, Ole32.DispatchID dispid)
        {
            if (!(obj is VSSDK.ICategorizeProperties catObj))
            {
                return(null);
            }

            VSSDK.PROPCAT categoryID = 0;
            if (catObj.MapPropertyToCategory(dispid, &categoryID) != HRESULT.S_OK)
            {
                return(null);
            }

            switch (categoryID)
            {
            case VSSDK.PROPCAT.Nil:
                return(string.Empty);

            case VSSDK.PROPCAT.Misc:
                return(SR.PropertyCategoryMisc);

            case VSSDK.PROPCAT.Font:
                return(SR.PropertyCategoryFont);

            case VSSDK.PROPCAT.Position:
                return(SR.PropertyCategoryPosition);

            case VSSDK.PROPCAT.Appearance:
                return(SR.PropertyCategoryAppearance);

            case VSSDK.PROPCAT.Behavior:
                return(SR.PropertyCategoryBehavior);

            case VSSDK.PROPCAT.Data:
                return(SR.PropertyCategoryData);

            case VSSDK.PROPCAT.List:
                return(SR.PropertyCategoryList);

            case VSSDK.PROPCAT.Text:
                return(SR.PropertyCategoryText);

            case VSSDK.PROPCAT.Scale:
                return(SR.PropertyCategoryScale);

            case VSSDK.PROPCAT.DDE:
                return(SR.PropertyCategoryDDE);
            }

            if (catObj.GetCategoryName(categoryID, Kernel32.GetThreadLocale(), out string categoryName) == HRESULT.S_OK)
            {
                return(categoryName);
            }

            return(null);
        }
Exemple #11
0
        internal static string GetDisplayString(Oleaut32.IPerPropertyBrowsing ppb, Ole32.DispatchID dispid, ref bool success)
        {
            HRESULT hr = ppb.GetDisplayString(dispid, out string strVal);

            if (hr != HRESULT.S_OK)
            {
                success = false;
                return(null);
            }

            success = strVal != null;
            return(strVal);
        }
        private unsafe Guid GetPropertyPageGuid(Ole32.IPerPropertyBrowsing target, Ole32.DispatchID dispid)
        {
            // check for a property page
            Guid    guid = Guid.Empty;
            HRESULT hr   = target.MapPropertyToPage(dispid, &guid);

            if (hr == HRESULT.S_OK)
            {
                return(guid);
            }

            return(Guid.Empty);
        }
Exemple #13
0
            object IReflect.InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
            {
                if (name.StartsWith("[DISPID="))
                {
                    int endIndex             = name.IndexOf(']');
                    Ole32.DispatchID dispid  = (Ole32.DispatchID) int.Parse(name.Substring(8, endIndex - 8), CultureInfo.InvariantCulture);
                    object           ambient = host.GetAmbientProperty(dispid);
                    if (ambient != null)
                    {
                        return(ambient);
                    }
                }

                throw E_FAIL;
            }
Exemple #14
0
        private unsafe void OnResetPropertyValue(Com2PropertyDescriptor sender, EventArgs e)
        {
            if (sender.TargetObject is NativeMethods.IVsPerPropertyBrowsing target)
            {
                Ole32.DispatchID dispid   = sender.DISPID;
                BOOL             canReset = BOOL.FALSE;
                HRESULT          hr       = target.CanResetPropertyValue(dispid, &canReset);
                if (hr.Succeeded())
                {
                    target.ResetPropertyValue(dispid);
                }
            }

            Debug.Assert(sender.TargetObject == null || sender.TargetObject is NativeMethods.IVsPerPropertyBrowsing, "Object is not " + Interface.Name + "!");
        }
Exemple #15
0
        /// <summary>
        ///  Retrieve the dispid of the property that we are to use as the name
        ///  member.  In this case, the grid will put parens around the name.
        /// </summary>
        public unsafe static Ole32.DispatchID GetNameDispId(UnsafeNativeMethods.IDispatch obj)
        {
            Ole32.DispatchID dispid = Ole32.DispatchID.UNKNOWN;
            string[]         names  = null;

            ComNativeDescriptor cnd = ComNativeDescriptor.Instance;
            bool succeeded          = false;

            // first try to find one with a valid value
            cnd.GetPropertyValue(obj, "__id", ref succeeded);

            if (succeeded)
            {
                names = new string[] { "__id" };
            }
            else
            {
                cnd.GetPropertyValue(obj, Ole32.DispatchID.Name, ref succeeded);
                if (succeeded)
                {
                    dispid = Ole32.DispatchID.Name;
                }
                else
                {
                    cnd.GetPropertyValue(obj, "Name", ref succeeded);
                    if (succeeded)
                    {
                        names = new string[] { "Name" };
                    }
                }
            }

            // now get the dispid of the one that worked...
            if (names != null)
            {
                Ole32.DispatchID pDispid = Ole32.DispatchID.UNKNOWN;
                Guid             g       = Guid.Empty;
                HRESULT          hr      = obj.GetIDsOfNames(&g, names, 1, Kernel32.GetThreadLocale(), &pDispid);
                if (hr.Succeeded())
                {
                    dispid = pDispid;
                }
            }

            return(dispid);
        }
Exemple #16
0
 internal object GetPropertyValue(object component, Ole32.DispatchID dispid, ref bool succeeded)
 {
     if (!(component is UnsafeNativeMethods.IDispatch))
     {
         return(null);
     }
     object[] pVarResult = new object[1];
     if (GetPropertyValue(component, dispid, pVarResult) == HRESULT.S_OK)
     {
         succeeded = true;
         return(pVarResult[0]);
     }
     else
     {
         succeeded = false;
         return(null);
     }
 }
Exemple #17
0
        internal unsafe HRESULT GetPropertyValue(object component, Ole32.DispatchID dispid, object[] retval)
        {
            if (!(component is UnsafeNativeMethods.IDispatch))
            {
                return(HRESULT.E_NOINTERFACE);
            }

            UnsafeNativeMethods.IDispatch iDispatch = (UnsafeNativeMethods.IDispatch)component;
            try
            {
                Guid g          = Guid.Empty;
                var  pExcepInfo = new Ole32.EXCEPINFO();
                var  dispParams = new Ole32.DISPPARAMS();
                try
                {
                    HRESULT hr = iDispatch.Invoke(
                        dispid,
                        &g,
                        Kernel32.GetThreadLocale(),
                        NativeMethods.DISPATCH_PROPERTYGET,
                        &dispParams,
                        retval,
                        &pExcepInfo,
                        null);
                    if (hr == HRESULT.DISP_E_EXCEPTION)
                    {
                        return(pExcepInfo.scode);
                    }

                    return(hr);
                }
                catch (ExternalException ex)
                {
                    return((HRESULT)ex.ErrorCode);
                }
            }
            catch
            {
            }

            return(HRESULT.E_FAIL);
        }
Exemple #18
0
        internal string GetName(object component)
        {
            if (!(component is UnsafeNativeMethods.IDispatch))
            {
                return("");
            }

            Ole32.DispatchID dispid = Com2TypeInfoProcessor.GetNameDispId((UnsafeNativeMethods.IDispatch)component);
            if (dispid != Ole32.DispatchID.UNKNOWN)
            {
                bool   success = false;
                object value   = GetPropertyValue(component, dispid, ref success);

                if (success && value != null)
                {
                    return(value.ToString());
                }
            }

            return(string.Empty);
        }
Exemple #19
0
        internal virtual void OnPropertyChanged(Ole32.DispatchID dispid)
        {
            try
            {
                ISite site = Host.Site;
                if (site != null)
                {
                    IComponentChangeService changeService = (IComponentChangeService)site.GetService(typeof(IComponentChangeService));

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

                        // Now notify the change service that the change was successful.
                        //
                        changeService.OnComponentChanged(Host, null, null, null);
                    }
                }
            }
            catch (Exception t)
            {
                Debug.Fail(t.ToString());
                throw;
            }
        }
 public HRESULT OnChanged(Ole32.DispatchID dispID) => throw new NotImplementedException();
        private unsafe bool GetBuilderGuidString(VSSDK.IProvidePropertyBuilder target, Ole32.DispatchID dispid, ref string strGuidBldr, VSSDK.CTLBLDTYPE *bldrType)
        {
            BOOL valid     = BOOL.FALSE;
            var  pGuidBldr = new string[1];

            if (!target.MapPropertyToBuilder(dispid, bldrType, pGuidBldr, &valid).Succeeded())
            {
                return(false);
            }

            if (valid.IsTrue() && (*bldrType & VSSDK.CTLBLDTYPE.FINTERNALBUILDER) == 0)
            {
                Debug.Fail("Property Browser doesn't support standard builders -- NYI");
                return(false);
            }

            strGuidBldr = pGuidBldr[0] ?? Guid.Empty.ToString();
            return(true);
        }
        internal unsafe static Attribute[] GetComponentAttributes(VSSDK.IVSMDPerPropertyBrowsing target, Ole32.DispatchID dispid)
        {
            uint   cItems = 0;
            IntPtr pbstrs = IntPtr.Zero;

            Oleaut32.VARIANT *pvars = null;

            HRESULT hr = target.GetPropertyAttributes(dispid, &cItems, &pbstrs, &pvars);

            if (hr != HRESULT.S_OK || cItems == 0 || pvars is null)
            {
                return(Array.Empty <Attribute>());
            }

            ArrayList attrs = new ArrayList();

            string[] attrTypeNames = GetStringsFromPtr(pbstrs, cItems);
            object[] varParams     = GetVariantsFromPtr(pvars, cItems);

            Debug.Assert(attrTypeNames.Length == varParams.Length, "Mismatched parameter and attribute name length");
            if (attrTypeNames.Length != varParams.Length)
            {
                return(Array.Empty <Attribute>());
            }

            // get the types
            Type[] types = new Type[attrTypeNames.Length];
            for (int i = 0; i < attrTypeNames.Length; i++)
            {
                string attrName = attrTypeNames[i];

                // try the name first
                Type     t = Type.GetType(attrName);
                Assembly a = null;

                if (t is not null)
                {
                    a = t.Assembly;
                }

                if (t is null)
                {
                    // check for an assembly name.
                    //
                    string assemblyName = string.Empty;

                    int comma = attrName.LastIndexOf(',');

                    if (comma != -1)
                    {
                        assemblyName = attrName.Substring(comma);
                        attrName     = attrName.Substring(0, comma);
                    }

                    string fieldName;
                    int    lastDot = attrName.LastIndexOf('.');
                    if (lastDot != -1)
                    {
                        fieldName = attrName.Substring(lastDot + 1);
                    }
                    else
                    {
                        // somethings odd
                        Debug.Fail("No dot in class name?");
                        continue;
                    }

                    // try to get the field value
                    if (a is null)
                    {
                        t = Type.GetType(attrName.Substring(0, lastDot) + assemblyName);
                    }
                    else
                    {
                        t = a.GetType(attrName.Substring(0, lastDot) + assemblyName);
                    }

                    if (t is null)
                    {
                        Debug.Fail("Failed load attribute '" + attrName + assemblyName + "'.  It's Type could not be found.");
                        continue;
                    }

                    Debug.Assert(typeof(Attribute).IsAssignableFrom(t), "Attribute type " + t.FullName + " does not derive from Attribute");
                    if (!typeof(Attribute).IsAssignableFrom(t))
                    {
                        continue;
                    }

                    if (t is not null)
                    {
                        FieldInfo fi = t.GetField(fieldName);

                        // only if it's static
                        if (fi is not null && fi.IsStatic)
                        {
                            object fieldValue = fi.GetValue(null);
                            if (fieldValue is Attribute)
                            {
                                // add it to the list
                                attrs.Add(fieldValue);
                                continue;
                            }
                        }
                        else
                        {
                            Debug.Fail("Couldn't load field '" + fieldName + "' from type '" + attrName.Substring(0, lastDot) + "'.  It does not exist or is not static");
                        }
                    }
                }

                Debug.Assert(typeof(Attribute).IsAssignableFrom(t), "Attribute type " + t.FullName + " does not derive from Attribute");
                if (!typeof(Attribute).IsAssignableFrom(t))
                {
                    continue;
                }

                Attribute attr = null;

                // okay, if we got here, we need to build the attribute...
                // get the initalizer value if we've got a one item ctor

                if (!Convert.IsDBNull(varParams[i]) && varParams[i] is not null)
                {
                    ConstructorInfo[] ctors = t.GetConstructors();
                    for (int c = 0; c < ctors.Length; c++)
                    {
                        ParameterInfo[] pis = ctors[c].GetParameters();
                        if (pis.Length == 1 && pis[0].ParameterType.IsAssignableFrom(varParams[i].GetType()))
                        {
                            // found a one-parameter ctor, use it
                            // try to construct a default one
                            try
                            {
                                attr = (Attribute)Activator.CreateInstance(t, new object[] { varParams[i] });
                                attrs.Add(attr);
                            }
                            catch
                            {
                                // nevermind
                                Debug.Fail("Attribute " + t.FullName + " did not have a initalizer specified and has no default constructor");
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    // try to construct a default one
                    try
                    {
                        attr = (Attribute)Activator.CreateInstance(t);
                        attrs.Add(attr);
                    }
                    catch
                    {
                        // nevermind
                        Debug.Fail("Attribute " + t.FullName + " did not have a initalizer specified and has no default constructor");
                        continue;
                    }
                }
            }
            internal unsafe void UpdateTypeConverterAndTypeEditorInternal(bool force, Ole32.DispatchID dispid)
            {
                // check to see if we're being forced here or if the work really
                // needs to be done.
                //
                if (GetFlag(FlagUpdatedEditorAndConverter) && !force)
                {
                    return;
                }

                if (owner.GetOcx() is null)
                {
                    return;
                }

                try
                {
                    Oleaut32.IPerPropertyBrowsing ppb = owner.GetPerPropertyBrowsing();

                    if (ppb != null)
                    {
                        bool hasStrings = false;

                        // check for enums
                        var caStrings = new Ole32.CA();
                        var caCookies = new Ole32.CA();

                        HRESULT hr = HRESULT.S_OK;
                        try
                        {
                            hr = ppb.GetPredefinedStrings(dispid, &caStrings, &caCookies);
                        }
                        catch (ExternalException ex)
                        {
                            hr = (HRESULT)ex.ErrorCode;
                            Debug.Fail("An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid=" +
                                       dispid + "), object type=" + new ComNativeDescriptor().GetClassName(ppb));
                        }

                        if (hr != HRESULT.S_OK)
                        {
                            hasStrings = false;
                            // Destroy the existing editor if we created the current one
                            // so if the items have disappeared, we don't hold onto the old
                            // items.
                            if (converter is Com2EnumConverter)
                            {
                                converter = null;
                            }
                        }
                        else
                        {
                            hasStrings = true;
                        }

                        if (hasStrings)
                        {
                            OleStrCAMarshaler stringMarshaler = new OleStrCAMarshaler(caStrings);
                            Int32CAMarshaler  intMarshaler    = new Int32CAMarshaler(caCookies);

                            if (stringMarshaler.Count > 0 && intMarshaler.Count > 0)
                            {
                                if (converter is null)
                                {
                                    converter = new AxEnumConverter(this, new AxPerPropertyBrowsingEnum(this, owner, stringMarshaler, intMarshaler, true));
                                }
                                else if (converter is AxEnumConverter)
                                {
                                    ((AxEnumConverter)converter).RefreshValues();
                                    if (((AxEnumConverter)converter).com2Enum is AxPerPropertyBrowsingEnum axEnum)
                                    {
                                        axEnum.RefreshArrays(stringMarshaler, intMarshaler);
                                    }
                                }
                            }
                            else
                            {
                                //hasStrings = false;
                            }
                        }
                        else
                        {
                            // if we didn't get any strings, try the proppage edtior
                            //
                            // Check to see if this is a property that we have already massaged to be a
                            // .Net type. If it is, don't bother with custom property pages. We already
                            // have a .Net Editor for this type.
                            //
                            ComAliasNameAttribute comAlias = (ComAliasNameAttribute)baseProp.Attributes[typeof(ComAliasNameAttribute)];
                            if (comAlias is null)
                            {
                                Guid g = GetPropertyPage(dispid);

                                if (!Guid.Empty.Equals(g))
                                {
                                    editor = new AxPropertyTypeEditor(this, g);

                                    // Show any non-browsable property that has an editor through a
                                    // property page.
                                    //
                                    if (!IsBrowsable)
                                    {
                                        Debug.WriteLineIf(AxPropTraceSwitch.TraceVerbose, "Making property: " + Name + " browsable because we found an editor.");
                                        AddAttribute(new BrowsableAttribute(true));
                                    }
                                }
                            }
                        }
                    }

                    SetFlag(FlagUpdatedEditorAndConverter, true);
                }
                catch (Exception e)
                {
                    Debug.WriteLineIf(AxPropTraceSwitch.TraceVerbose, "could not get the type editor for property: " + Name + " Exception: " + e);
                }
            }
 public HRESULT OnRequestEdit(Ole32.DispatchID dispID) => throw new NotImplementedException();
Exemple #25
0
        internal static string GetDisplayString(NativeMethods.IPerPropertyBrowsing ppb, Ole32.DispatchID dispid, ref bool success)
        {
            var     strVal = new string[1];
            HRESULT hr     = ppb.GetDisplayString(dispid, strVal);

            if (hr != HRESULT.S_OK)
            {
                success = false;
                return(null);
            }

            success = strVal[0] != null;
            return(strVal[0]);
        }
Exemple #26
0
 HRESULT Ole32.IPropertyNotifySink.OnRequestEdit(Ole32.DispatchID dispid)
 {
     return(HRESULT.S_OK);
 }
Exemple #27
0
            // IPropertyNotifySink methods

            HRESULT Ole32.IPropertyNotifySink.OnChanged(Ole32.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 != Ole32.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 coEx;
                            }

                            // 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 t;
                }
                finally
                {
                    host.NoComponentChangeEvents--;
                }

                return(HRESULT.S_OK);
            }
        private string GetCategoryFromObject(object obj, Ole32.DispatchID dispid)
        {
            if (obj == null)
            {
                return(null);
            }

            if (obj is NativeMethods.ICategorizeProperties catObj)
            {
                try
                {
                    int categoryID = 0;

                    if (catObj.MapPropertyToCategory(dispid, ref categoryID) == HRESULT.S_OK)
                    {
                        switch (categoryID)
                        {
                        case NativeMethods.ActiveX.PROPCAT_Nil:
                            return("");

                        case NativeMethods.ActiveX.PROPCAT_Misc:
                            return(SR.PropertyCategoryMisc);

                        case NativeMethods.ActiveX.PROPCAT_Font:
                            return(SR.PropertyCategoryFont);

                        case NativeMethods.ActiveX.PROPCAT_Position:
                            return(SR.PropertyCategoryPosition);

                        case NativeMethods.ActiveX.PROPCAT_Appearance:
                            return(SR.PropertyCategoryAppearance);

                        case NativeMethods.ActiveX.PROPCAT_Behavior:
                            return(SR.PropertyCategoryBehavior);

                        case NativeMethods.ActiveX.PROPCAT_Data:
                            return(SR.PropertyCategoryData);

                        case NativeMethods.ActiveX.PROPCAT_List:
                            return(SR.PropertyCategoryList);

                        case NativeMethods.ActiveX.PROPCAT_Text:
                            return(SR.PropertyCategoryText);

                        case NativeMethods.ActiveX.PROPCAT_Scale:
                            return(SR.PropertyCategoryScale);

                        case NativeMethods.ActiveX.PROPCAT_DDE:
                            return(SR.PropertyCategoryDDE);
                        }

                        if (NativeMethods.S_OK == catObj.GetCategoryName(categoryID, CultureInfo.CurrentCulture.LCID, out string categoryName))
                        {
                            return(categoryName);
                        }
                    }
                }
                catch
                {
                }
            }
            return(null);
        }
Exemple #29
0
 HRESULT Ole32.IPropertyNotifySink.OnRequestEdit(Ole32.DispatchID dispid)
 {
     Debug.WriteLineIf(AxHTraceSwitch.TraceVerbose, "in OnRequestEdit for " + host.ToString());
     return(HRESULT.S_OK);
 }