private bool GetBuilderGuidString(NativeMethods.IProvidePropertyBuilder target, int dispid, ref string strGuidBldr, int[] bldrType)
        {
            bool valid = false;

            string[] pGuidBldr = new string[1];
            if (NativeMethods.Failed(target.MapPropertyToBuilder(dispid, bldrType, pGuidBldr, ref valid)))
            {
                valid = false;
            }

            if (valid && (bldrType[0] & _CTLBLDTYPE.CTLBLDTYPE_FINTERNALBUILDER) == 0)
            {
                valid = false;
                Debug.Fail("Property Browser doesn't support standard builders -- NYI");
            }

            if (!valid)
            {
                return(false);
            }

            if (pGuidBldr[0] == null)
            {
                strGuidBldr = Guid.Empty.ToString();
            }
            else
            {
                strGuidBldr = pGuidBldr[0];
            }
            return(true);
        }
        private bool GetBuilderGuidString(NativeMethods.IProvidePropertyBuilder target, int dispid, ref string strGuidBldr, int[] bldrType)
        {
            bool builderAvailable = false;

            string[] pbstrGuidBldr = new string[1];
            if (NativeMethods.Failed(target.MapPropertyToBuilder(dispid, bldrType, pbstrGuidBldr, ref builderAvailable)))
            {
                builderAvailable = false;
            }
            if (builderAvailable && ((bldrType[0] & 2) == 0))
            {
                builderAvailable = false;
            }
            if (!builderAvailable)
            {
                return(false);
            }
            if (pbstrGuidBldr[0] == null)
            {
                strGuidBldr = Guid.Empty.ToString();
            }
            else
            {
                strGuidBldr = pbstrGuidBldr[0];
            }
            return(true);
        }
        /// <summary>
        ///     Takes the value returned from valueAccess.getValue() and modifies or replaces
        ///     the value, passing the result into valueAccess.setValue().  This is where
        ///     an editor can launch a modal dialog or create a drop down editor to allow
        ///     the user to modify the value.  Host assistance in presenting UI to the user
        ///     can be found through the valueAccess.getService function.
        /// </summary>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IntPtr parentHandle = (IntPtr)UnsafeNativeMethods.GetFocus();

            IUIService uiSvc = (IUIService)provider.GetService(typeof(IUIService));

            if (uiSvc != null)
            {
                IWin32Window parent = uiSvc.GetDialogOwnerWindow();
                if (parent != null)
                {
                    parentHandle = parent.Handle;
                }
            }

            bool useValue = false;
            //VARIANT pValue = null;
            object pValue = value;

            try
            {
                object obj = propDesc.TargetObject;


                if (obj is ICustomTypeDescriptor)
                {
                    obj = ((ICustomTypeDescriptor)obj).GetPropertyOwner(propDesc);
                }


                Debug.Assert(obj is NativeMethods.IProvidePropertyBuilder, "object is not IProvidePropertyBuilder");
                NativeMethods.IProvidePropertyBuilder propBuilder = (NativeMethods.IProvidePropertyBuilder)obj;

                if (NativeMethods.Failed(propBuilder.ExecuteBuilder(propDesc.DISPID,
                                                                    guidString,
                                                                    null,
                                                                    new HandleRef(null, parentHandle),
                                                                    ref pValue, ref useValue)))
                {
                    useValue = false;
                }
            }
            catch (ExternalException ex)
            {
                Debug.Fail("Failed to show property frame: " + ex.ErrorCode.ToString(CultureInfo.InvariantCulture));
            }

            if (useValue && (bldrType & _CTLBLDTYPE.CTLBLDTYPE_FEDITSOBJDIRECTLY) == 0)
            {
                return(pValue);//pValue.ToVariant();
            }
            return(value);
        }
 private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent)
 {
     NativeMethods.IProvidePropertyBuilder targetObject = sender.TargetObject as NativeMethods.IProvidePropertyBuilder;
     if (targetObject != null)
     {
         string strGuidBldr = null;
         bool   flag        = this.GetBuilderGuidString(targetObject, sender.DISPID, ref strGuidBldr, new int[1]);
         if ((sender.CanShow && flag) && typeof(UnsafeNativeMethods.IDispatch).IsAssignableFrom(sender.PropertyType))
         {
             attrEvent.Add(BrowsableAttribute.Yes);
         }
     }
 }
        private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
        {
            object targetObject = sender.TargetObject;

            if (targetObject is NativeMethods.IProvidePropertyBuilder)
            {
                NativeMethods.IProvidePropertyBuilder target = (NativeMethods.IProvidePropertyBuilder)targetObject;
                int[]  bldrType    = new int[1];
                string strGuidBldr = null;
                if (this.GetBuilderGuidString(target, sender.DISPID, ref strGuidBldr, bldrType))
                {
                    gveevent.TypeEditor = new Com2PropertyBuilderUITypeEditor(sender, strGuidBldr, bldrType[0], (UITypeEditor)gveevent.TypeEditor);
                }
            }
        }
        private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
        {
            object target = sender.TargetObject;

            if (target is NativeMethods.IProvidePropertyBuilder)
            {
                NativeMethods.IProvidePropertyBuilder propBuilder = (NativeMethods.IProvidePropertyBuilder)target;
                int[]  pctlBldType = new int[1];
                string guidString  = null;

                if (GetBuilderGuidString(propBuilder, sender.DISPID, ref guidString, pctlBldType))
                {
                    gveevent.TypeEditor = new Com2PropertyBuilderUITypeEditor(sender, guidString, pctlBldType[0], (UITypeEditor)gveevent.TypeEditor);
                }
            }
        }
        /// <summary>
        /// Here is where we handle IVsPerPropertyBrowsing.GetLocalizedPropertyInfo and IVsPerPropertyBrowsing.   HideProperty
        /// such as IPerPropertyBrowsing, IProvidePropertyBuilder, etc.
        /// </summary>
        private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent)
        {
            NativeMethods.IProvidePropertyBuilder target = sender.TargetObject as NativeMethods.IProvidePropertyBuilder;

            if (target != null)
            {
                string s            = null;
                bool   builderValid = GetBuilderGuidString(target, sender.DISPID, ref s, new int[1]);
                // we hide IDispatch props by default, we we need to force showing them here
                if (sender.CanShow && builderValid)
                {
                    if (typeof(UnsafeNativeMethods.IDispatch).IsAssignableFrom(sender.PropertyType))
                    {
                        attrEvent.Add(BrowsableAttribute.Yes);
                    }
                }
            }
        }
예제 #8
0
        private unsafe bool GetBuilderGuidString(NativeMethods.IProvidePropertyBuilder target, Ole32.DispatchID dispid, ref string strGuidBldr, int[] bldrType)
        {
            BOOL valid     = BOOL.FALSE;
            var  pGuidBldr = new string[1];

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

            if (valid.IsTrue() && (bldrType[0] & _CTLBLDTYPE.CTLBLDTYPE_FINTERNALBUILDER) == 0)
            {
                Debug.Fail("Property Browser doesn't support standard builders -- NYI");
                return(false);
            }

            strGuidBldr = pGuidBldr[0] ?? Guid.Empty.ToString();
            return(true);
        }