public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet)
 {
     cancelSet = false;
     if (((this.lastManaged != null) && this.lastManaged.Equals(managedValue)) && ((this.pictureRef != null) && this.pictureRef.IsAlive))
     {
         return this.pictureRef.Target;
     }
     this.lastManaged = managedValue;
     if (managedValue != null)
     {
         Guid gUID = typeof(System.Windows.Forms.UnsafeNativeMethods.IPicture).GUID;
         System.Windows.Forms.NativeMethods.PICTDESC pictdesc = null;
         bool fOwn = false;
         if (this.lastManaged is Icon)
         {
             pictdesc = System.Windows.Forms.NativeMethods.PICTDESC.CreateIconPICTDESC(((Icon) this.lastManaged).Handle);
         }
         else if (this.lastManaged is Bitmap)
         {
             pictdesc = System.Windows.Forms.NativeMethods.PICTDESC.CreateBitmapPICTDESC(((Bitmap) this.lastManaged).GetHbitmap(), this.lastPalette);
             fOwn = true;
         }
         System.Windows.Forms.UnsafeNativeMethods.IPicture target = System.Windows.Forms.UnsafeNativeMethods.OleCreatePictureIndirect(pictdesc, ref gUID, fOwn);
         this.lastNativeHandle = target.GetHandle();
         this.pictureRef = new WeakReference(target);
         return target;
     }
     this.lastManaged = null;
     this.lastNativeHandle = this.lastPalette = IntPtr.Zero;
     this.pictureRef = null;
     return null;
 }
 public Com2PictureConverter(Com2PropertyDescriptor pd)
 {
     if ((pd.DISPID == -522) || (pd.Name.IndexOf("Icon") != -1))
     {
         this.pictureType = typeof(Icon);
     }
 }
        public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd)
        {
            if (nativeValue == null)
            {
                return null;
            }
            System.Windows.Forms.UnsafeNativeMethods.IPicture target = (System.Windows.Forms.UnsafeNativeMethods.IPicture) nativeValue;
            IntPtr handle = target.GetHandle();
            if ((this.lastManaged == null) || (handle != this.lastNativeHandle))
            {
                this.lastNativeHandle = handle;
                if (!(handle != IntPtr.Zero))
                {
                    this.lastManaged = null;
                    this.pictureRef = null;
                }
                else
                {
                    switch (target.GetPictureType())
                    {
                        case 1:
                            this.pictureType = typeof(Bitmap);
                            this.lastManaged = Image.FromHbitmap(handle);
                            break;

                        case 3:
                            this.pictureType = typeof(Icon);
                            this.lastManaged = Icon.FromHandle(handle);
                            break;
                    }
                    this.pictureRef = new WeakReference(target);
                }
            }
            return this.lastManaged;
        }
        private void OnGetAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent) {

            string cat = GetCategoryFromObject(sender.TargetObject, sender.DISPID);

            if (cat != null && cat.Length > 0) {
                attrEvent.Add(new CategoryAttribute(cat));
            }
        }
 public override void SetupPropertyHandlers(Com2PropertyDescriptor[] propDesc) {
     if (propDesc == null) {
         return;
     }
     for (int i = 0; i < propDesc.Length; i++) {
         propDesc[i].QueryGetBaseAttributes += new GetAttributesEventHandler(this.OnGetAttributes);
     }
 }
 public Com2Properties(object obj, Com2PropertyDescriptor[] props, int defaultIndex)
 {
     this.SetProps(props);
     this.weakObjRef = new WeakReference(obj);
     this.defaultIndex = defaultIndex;
     this.typeInfoVersions = this.GetTypeInfoVersions(obj);
     this.touchedTime = DateTime.Now.Ticks;
 }
 public static bool AllowChildProperties(Com2PropertyDescriptor propDesc) {
    if (propDesc.TargetObject is NativeMethods.IVsPerPropertyBrowsing) {
       bool pfHide = false;
       int hr = ((NativeMethods.IVsPerPropertyBrowsing)propDesc.TargetObject).DisplayChildProperties(propDesc.DISPID, ref pfHide);
       return (hr == NativeMethods.S_OK && pfHide);
    }
    return false;
 }
 public static bool AllowChildProperties(Com2PropertyDescriptor propDesc)
 {
     if (!(propDesc.TargetObject is NativeMethods.IVsPerPropertyBrowsing))
     {
         return false;
     }
     bool pfDisplay = false;
     return ((((NativeMethods.IVsPerPropertyBrowsing) propDesc.TargetObject).DisplayChildProperties(propDesc.DISPID, ref pfDisplay) == 0) && pfDisplay);
 }
 private void OnGetIsReadOnly(Com2PropertyDescriptor sender, GetBoolValueEvent gbvevent)
 {
     if (sender.TargetObject is NativeMethods.IVsPerPropertyBrowsing)
     {
         NativeMethods.IVsPerPropertyBrowsing targetObject = (NativeMethods.IVsPerPropertyBrowsing) sender.TargetObject;
         if (targetObject.IsPropertyReadOnly(sender.DISPID, false) == 0)
         {
             gbvevent.Value = fReadOnly;
         }
     }
 }
 public override void SetupPropertyHandlers(Com2PropertyDescriptor[] propDesc)
 {
     if (propDesc != null)
     {
         for (int i = 0; i < propDesc.Length; i++)
         {
             propDesc[i].QueryGetBaseAttributes += new GetAttributesEventHandler(this.OnGetBaseAttributes);
             propDesc[i].QueryGetTypeConverterAndTypeEditor += new GetTypeConverterAndTypeEditorEventHandler(this.OnGetTypeConverterAndTypeEditor);
         }
     }
 }
 private void OnGetDisplayName(Com2PropertyDescriptor sender, GetNameItemEvent nameItem)
 {
     if (sender.TargetObject is NativeMethods.IVsPerPropertyBrowsing)
     {
         NativeMethods.IVsPerPropertyBrowsing targetObject = (NativeMethods.IVsPerPropertyBrowsing) sender.TargetObject;
         string[] pbstrLocalizedName = new string[1];
         if ((targetObject.GetLocalizedPropertyInfo(sender.DISPID, CultureInfo.CurrentCulture.LCID, pbstrLocalizedName, null) == 0) && (pbstrLocalizedName[0] != null))
         {
             nameItem.Name = pbstrLocalizedName[0];
         }
     }
 }
 private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent)
 {
     NativeMethods.IVsPerPropertyBrowsing targetObject = sender.TargetObject as NativeMethods.IVsPerPropertyBrowsing;
     if (targetObject != null)
     {
         string[] pbstrLocalizeDescription = new string[1];
         if ((targetObject.GetLocalizedPropertyInfo(sender.DISPID, CultureInfo.CurrentCulture.LCID, null, pbstrLocalizeDescription) == 0) && (pbstrLocalizeDescription[0] != null))
         {
             attrEvent.Add(new DescriptionAttribute(pbstrLocalizeDescription[0]));
         }
     }
 }
 private void OnCanResetPropertyValue(Com2PropertyDescriptor sender, GetBoolValueEvent boolEvent)
 {
     if (sender.TargetObject is NativeMethods.IVsPerPropertyBrowsing)
     {
         NativeMethods.IVsPerPropertyBrowsing targetObject = (NativeMethods.IVsPerPropertyBrowsing) sender.TargetObject;
         bool pfCanReset = boolEvent.Value;
         if (NativeMethods.Succeeded(targetObject.CanResetPropertyValue(sender.DISPID, ref pfCanReset)))
         {
             boolEvent.Value = pfCanReset;
         }
     }
 }
 private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent)
 {
     System.Windows.Forms.NativeMethods.IPerPropertyBrowsing targetObject = sender.TargetObject as System.Windows.Forms.NativeMethods.IPerPropertyBrowsing;
     if (targetObject != null)
     {
         bool flag = !Guid.Empty.Equals(this.GetPropertyPageGuid(targetObject, sender.DISPID));
         if ((sender.CanShow && flag) && typeof(UnsafeNativeMethods.IDispatch).IsAssignableFrom(sender.PropertyType))
         {
             attrEvent.Add(BrowsableAttribute.Yes);
         }
     }
 }
        /// <include file='doc\COM2IManagedPerPropertyBrowsingHandler.uex' path='docs/doc[@for="Com2IManagedPerPropertyBrowsingHandler.OnGetAttributes"]/*' />
        /// <devdoc>
        /// Here is where we handle IVsPerPropertyBrowsing.GetLocalizedPropertyInfo and IVsPerPropertyBrowsing.   HideProperty
        /// such as IPerPropertyBrowsing, IProvidePropertyBuilder, etc.
        /// </devdoc>
        private void OnGetAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent) {
            Object target = sender.TargetObject;

            if (target is NativeMethods.IManagedPerPropertyBrowsing) {
                Attribute[] attrs = GetComponentAttributes((NativeMethods.IManagedPerPropertyBrowsing)target,sender.DISPID);
                if (attrs != null) {
                    for (int i = 0; i < attrs.Length; i++) {
                        attrEvent.Add(attrs[i]);
                    }
                }
            }
        }
 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);
         }
     }
 }
 public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd)
 {
     int oleColor = 0;
     if (nativeValue is uint)
     {
         oleColor = (int) ((uint) nativeValue);
     }
     else if (nativeValue is int)
     {
         oleColor = (int) nativeValue;
     }
     return ColorTranslator.FromOle(oleColor);
 }
        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);
                }
            }
        }
 public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet)
 {
     cancelSet = false;
     if (managedValue == null)
     {
         managedValue = Color.Black;
     }
     if (managedValue is Color)
     {
         return ColorTranslator.ToOle((Color) managedValue);
     }
     return 0;
 }
         private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent){
             NativeMethods.IVsPerPropertyBrowsing vsObj = sender.TargetObject as NativeMethods.IVsPerPropertyBrowsing;

             if (vsObj == null) {
                 return;
             }

             // should we localize this?
             string[] pHelpString = new string[1];
             int hr = vsObj.GetLocalizedPropertyInfo(sender.DISPID, CultureInfo.CurrentCulture.LCID, null, pHelpString);
             if (hr == NativeMethods.S_OK && pHelpString[0] != null){
                attrEvent.Add(new DescriptionAttribute(pHelpString[0]));
             }
         }
 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);
         }
     }
 }
        /// <include file='doc\COM2IProvidePropertyBuilderHandler.uex' path='docs/doc[@for="Com2IProvidePropertyBuilderHandler.OnGetAttributes"]/*' />
        /// <devdoc>
        /// Here is where we handle IVsPerPropertyBrowsing.GetLocalizedPropertyInfo and IVsPerPropertyBrowsing.   HideProperty
        /// such as IPerPropertyBrowsing, IProvidePropertyBuilder, etc.
        /// </devdoc>
        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);
                    }
                }
            }
        }
 /// <include file='doc\COM2IPerPropertyBrowsingHandler.uex' path='docs/doc[@for="Com2IPerPropertyBrowsingHandler.OnGetAttributes"]/*' />
 /// <devdoc>
 /// Here is where we handle IVsPerPropertyBrowsing.GetLocalizedPropertyInfo and IVsPerPropertyBrowsing.   HideProperty
 /// such as IPerPropertyBrowsing, IProvidePropertyBuilder, etc.
 /// </devdoc>
 private void OnGetBaseAttributes(Com2PropertyDescriptor sender, GetAttributesEvent attrEvent) {
     NativeMethods.IPerPropertyBrowsing target = sender.TargetObject as NativeMethods.IPerPropertyBrowsing;
     if (target != null) {
         // we hide IDispatch props by default, we we need to force showing them here
                                                           
         bool validPropPage = !Guid.Empty.Equals(GetPropertyPageGuid(target, sender.DISPID));
         
         if (sender.CanShow && validPropPage) {
             if (typeof(UnsafeNativeMethods.IDispatch).IsAssignableFrom(sender.PropertyType)) {
                 attrEvent.Add(BrowsableAttribute.Yes);
             }
         }
     }
 }
Exemplo n.º 24
0
         /// <include file='doc\COM2ColorConverter.uex' path='docs/doc[@for="Com2ColorConverter.ConvertNativeToManaged"]/*' />
         /// <devdoc>
         ///     Converts the native value into a managed value
         /// </devdoc>
         public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd){
               object baseValue = nativeValue;
               int intVal = 0;

               // get the integer value out of the native...
               //
               if (nativeValue is UInt32){
                  intVal = (int)(UInt32)nativeValue;
               }
               else if (nativeValue is Int32){
                  intVal = (int)nativeValue;
               }

               return ColorTranslator.FromOle(intVal);
         }
 private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
 {
     if (sender.TargetObject is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
     {
         System.Windows.Forms.NativeMethods.IPerPropertyBrowsing targetObject = (System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) sender.TargetObject;
         bool flag = false;
         System.Windows.Forms.NativeMethods.CA_STRUCT pCaStringsOut = new System.Windows.Forms.NativeMethods.CA_STRUCT();
         System.Windows.Forms.NativeMethods.CA_STRUCT pCaCookiesOut = new System.Windows.Forms.NativeMethods.CA_STRUCT();
         int errorCode = 0;
         try
         {
             errorCode = targetObject.GetPredefinedStrings(sender.DISPID, pCaStringsOut, pCaCookiesOut);
         }
         catch (ExternalException exception)
         {
             errorCode = exception.ErrorCode;
         }
         if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter)
         {
             gveevent.TypeConverter = null;
         }
         if (errorCode != 0)
         {
             flag = false;
         }
         else
         {
             flag = true;
         }
         if (flag)
         {
             OleStrCAMarshaler names = new OleStrCAMarshaler(pCaStringsOut);
             Int32CAMarshaler values = new Int32CAMarshaler(pCaCookiesOut);
             if ((names.Count > 0) && (values.Count > 0))
             {
                 gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, this, names, values, true));
             }
         }
         if (!flag && !sender.ConvertingNativeType)
         {
             Guid propertyPageGuid = this.GetPropertyPageGuid(targetObject, sender.DISPID);
             if (!Guid.Empty.Equals(propertyPageGuid))
             {
                 gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, propertyPageGuid, (UITypeEditor) gveevent.TypeEditor);
             }
         }
     }
 }
Exemplo n.º 26
0
         /// <include file='doc\COM2ColorConverter.uex' path='docs/doc[@for="Com2ColorConverter.ConvertManagedToNative"]/*' />
         /// <devdoc>
         ///     Converts the managed value into a native value
         /// </devdoc>
         public override object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet){
               // don't cancel the set
               cancelSet = false;

               // we default to black.
               //
               if (managedValue == null){
                  managedValue = Color.Black;
               }

               if (managedValue is Color){
                  return ColorTranslator.ToOle(((Color)managedValue));

               }
               Debug.Fail("Don't know how to set type:" + managedValue.GetType().Name);
               return 0;
         }
 private void OnGetDisplayValue(Com2PropertyDescriptor sender, GetNameItemEvent gnievent)
 {
     try
     {
         if ((sender.TargetObject is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) && (!(sender.Converter is Com2IPerPropertyEnumConverter) && !sender.ConvertingNativeType))
         {
             bool success = true;
             string str = GetDisplayString((System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) sender.TargetObject, sender.DISPID, ref success);
             if (success)
             {
                 gnievent.Name = str;
             }
         }
     }
     catch
     {
     }
 }
 /// <include file='doc\COM2IVsPerPropertyBrowsingHandler.uex' path='docs/doc[@for="Com2IVsPerPropertyBrowsingHandler.SetupPropertyHandlers"]/*' />
 /// <devdoc>
 /// Called to setup the property handlers on a given properties
 /// In this method, the handler will add listeners to the events that
 /// the Com2PropertyDescriptor surfaces that it cares about.
 /// </devdoc>
 public override void SetupPropertyHandlers(Com2PropertyDescriptor[] propDesc){
       if (propDesc == null){
          return;
       }
       for (int i = 0; i < propDesc.Length; i++){
          propDesc[i].QueryGetDynamicAttributes += new GetAttributesEventHandler(this.OnGetDynamicAttributes);
          propDesc[i].QueryGetBaseAttributes += new GetAttributesEventHandler(this.OnGetBaseAttributes);
          propDesc[i].QueryGetDisplayName += new GetNameItemEventHandler(this.OnGetDisplayName);
          propDesc[i].QueryGetIsReadOnly += new GetBoolValueEventHandler(this.OnGetIsReadOnly);
          
          propDesc[i].QueryShouldSerializeValue += new GetBoolValueEventHandler(this.OnShouldSerializeValue);
          propDesc[i].QueryCanResetValue += new GetBoolValueEventHandler(this.OnCanResetPropertyValue);
          propDesc[i].QueryResetValue += new Com2EventHandler(this.OnResetPropertyValue);
          
          propDesc[i].QueryGetTypeConverterAndTypeEditor += new GetTypeConverterAndTypeEditorEventHandler(this.OnGetTypeConverterAndTypeEditor);
          
       }
 }
Exemplo n.º 29
0
        public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd) {
            // we're getting an IFont thing here
            UnsafeNativeMethods.IFont nativeFont = nativeValue as UnsafeNativeMethods.IFont;

            if (nativeFont == null) {
                lastHandle = IntPtr.Zero;
                lastFont = Control.DefaultFont;
                return lastFont;
            }

            IntPtr fontHandle = nativeFont.GetHFont();

            // see if we have this guy cached
            if (fontHandle == lastHandle && lastFont != null) {
                return lastFont;
            }

            lastHandle = fontHandle;
            
            try {
                // this wasn't working because it was converting everything to 
                // world units.
                //
                Font font = Font.FromHfont(lastHandle);
                try {
                    lastFont = ControlPaint.FontInPoints(font);
                } 
                finally {
                    font.Dispose();
                }
            }
            catch(ArgumentException) {
                // we will fail on non-truetype fonts, so 
                // just use the default font.
                lastFont = Control.DefaultFont;
            }
            
            return lastFont;
        }
        public override object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd) {

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

            Debug.Assert(nativeValue is UnsafeNativeMethods.IPicture, "nativevalue is not IPicture");

            UnsafeNativeMethods.IPicture nativePicture = (UnsafeNativeMethods.IPicture)nativeValue;
            IntPtr handle = nativePicture.GetHandle();

            if (lastManaged != null && handle == lastNativeHandle) {
                return lastManaged;
            }

            lastNativeHandle = handle;
            //lastPalette = nativePicture.GetHPal();
            if (handle != IntPtr.Zero) {
                switch (nativePicture.GetPictureType()) {
                    case  NativeMethods.Ole.PICTYPE_ICON:
                        pictureType = typeof(Icon);
                        lastManaged = Icon.FromHandle(handle);
                        break;
                    case   NativeMethods.Ole.PICTYPE_BITMAP:
                        pictureType = typeof(Bitmap);
                        lastManaged = Image.FromHbitmap(handle);
                        break;
                    default:
                        Debug.Fail("Unknown picture type");
			break;
                }
                pictureRef = new WeakReference(nativePicture);
            }
            else {
                lastManaged = null;
                pictureRef = null;
            }
            return lastManaged;
        }
 public abstract object ConvertNativeToManaged(object nativeValue, Com2PropertyDescriptor pd);
 public abstract object ConvertManagedToNative(object managedValue, Com2PropertyDescriptor pd, ref bool cancelSet);
Exemplo n.º 33
0
 public Com2PropertyBuilderUITypeEditor(Com2PropertyDescriptor pd, string guidString, VSSDK.CTLBLDTYPE type, UITypeEditor baseEditor) : base(baseEditor)
 {
     propDesc        = pd;
     this.guidString = guidString;
     bldrType        = type;
 }
Exemplo n.º 34
0
 public Com2IDispatchConverter(Com2PropertyDescriptor propDesc, bool allowExpand) : base(propDesc.PropertyType)
 {
     this.propDesc    = propDesc;
     this.allowExpand = allowExpand;
 }
        private void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
        {
            if (sender.TargetObject is NativeMethods.IPerPropertyBrowsing)
            {
                NativeMethods.IPerPropertyBrowsing ppb = (NativeMethods.IPerPropertyBrowsing)sender.TargetObject;

                bool hasStrings = false;

                // check for enums
                NativeMethods.CA_STRUCT caStrings = new NativeMethods.CA_STRUCT();
                NativeMethods.CA_STRUCT caCookies = new NativeMethods.CA_STRUCT();

                int hr = NativeMethods.S_OK;

                try {
                    hr = ppb.GetPredefinedStrings(sender.DISPID, caStrings, caCookies);
                }
                catch (ExternalException ex) {
                    hr = ex.ErrorCode;
                    Debug.Fail("An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid=" + sender.DISPID + "), object type=" + new ComNativeDescriptor().GetClassName(ppb) + ".  This is caused by an exception (usually an AV) inside the object being browsed, and is not a problem in the properties window.");
                }

                // Terminate the existing editor if we created the current one
                // so if the items have disappeared, we don't hold onto the old
                // items.
                if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter)
                {
                    gveevent.TypeConverter = null;
                }

                if (hr != NativeMethods.S_OK)
                {
                    hasStrings = false;
                }
                else
                {
                    hasStrings = true;
                }

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


                    if (stringMarshaler.Count > 0 && intMarshaler.Count > 0)
                    {
                        gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, this, stringMarshaler, intMarshaler, true));
                    }
                    else
                    {
                        //hasStrings = false;
                    }
                }

                // if we didn't get any strings, try the proppage edtior
                //
                if (!hasStrings)
                {
                    // this is a _bit_ of a backwards-compat work around...
                    // many older ActiveX controls will show a property page
                    // for all properties since the old grid would only put up the
                    // [...] button for "(Custom)".  If we have a conversion editor,
                    // don't allow this to override it...
                    //
                    if (sender.ConvertingNativeType)
                    {
                        return;
                    }

                    Guid g = GetPropertyPageGuid(ppb, sender.DISPID);

                    if (!Guid.Empty.Equals(g))
                    {
                        gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, g, (UITypeEditor)gveevent.TypeEditor);
                    }
                }
            }
        }
        private unsafe void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent)
        {
            if (sender.TargetObject is not Oleaut32.IPerPropertyBrowsing ppb)
            {
                return;
            }

            // check for enums
            Ole32.CALPOLESTR caStrings = default;
            Ole32.CADWORD    caCookies = default;

            HRESULT hr;

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

            // Terminate the existing editor if we created the current one so if the items have disappeared,
            // we don't hold onto the old items.
            if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter)
            {
                gveevent.TypeConverter = null;
            }

            if (hr == HRESULT.S_OK)
            {
                string?[] names   = caStrings.ConvertAndFree();
                uint[]    cookies = caCookies.ConvertAndFree();

                if (names.Length > 0 && cookies.Length > 0)
                {
                    gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, names, cookies));
                }
            }
            else
            {
                // If we didn't get any strings, try the proppage editor
                //
                // This is a bit of a backwards-compat work around. Many older ActiveX controls will show a
                // property page for all properties since the old grid would only put up the [...] button for
                // "(Custom)".  If we have a conversion editor, don't allow this to override it.

                if (sender.ConvertingNativeType)
                {
                    return;
                }

                Guid guid = GetPropertyPageGuid(ppb, sender.DISPID);

                if (!Guid.Empty.Equals(guid))
                {
                    gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, guid, (UITypeEditor)gveevent.TypeEditor);
                }
            }
        }
Exemplo n.º 37
0
 /// <summary>
 /// Called to setup the property handlers on a given property
 /// In this method, the handler will add listeners to the events that
 /// the COM2PropertyDescriptor surfaces that it cares about.
 /// </summary>
 public virtual void SetupPropertyHandlers(Com2PropertyDescriptor propDesc)
 {
     SetupPropertyHandlers(new Com2PropertyDescriptor[] { propDesc });
 }
Exemplo n.º 38
0
 public Com2PropertyBuilderUITypeEditor(Com2PropertyDescriptor pd, string guidString, int type) : this(pd, guidString, type, pd.PropertyType)
 {
 }
Exemplo n.º 39
0
 public Com2PropertyBuilderUITypeEditor(Com2PropertyDescriptor pd, string guidString, int type, UITypeEditor baseEditor) : base(baseEditor)
 {
     propDesc        = pd;
     this.guidString = guidString;
     this.bldrType   = type;
 }
 public Com2PropertyPageUITypeEditor(Com2PropertyDescriptor pd, Guid guid, UITypeEditor baseEditor) : base(baseEditor)
 {
     propDesc  = pd;
     this.guid = guid;
 }
Exemplo n.º 41
0
 public Com2IDispatchConverter(Com2PropertyDescriptor propDesc, bool allowExpand, TypeConverter baseConverter) : base(baseConverter)
 {
     this.propDesc    = propDesc;
     this.allowExpand = allowExpand;
 }
 public Com2PropertyPageUITypeEditor(Com2PropertyDescriptor pd, Guid guid) : this(pd, guid, pd.PropertyType)
 {
     propDesc  = pd;
     this.guid = guid;
 }
Exemplo n.º 43
0
        public static Com2Properties GetProperties(object obj)
        {
            Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties");

            if (obj is null || !Marshal.IsComObject(obj))
            {
                Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties returning null: Object is not a com Object");
                return(null);
            }

            ITypeInfo[] typeInfos = FindTypeInfos(obj, false);

            // oops, looks like this guy doesn't surface any type info
            // this is okay, so we just say it has no props
            if (typeInfos is null || typeInfos.Length == 0)
            {
                Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties :: Didn't get typeinfo");
                return(null);
            }

            int       defaultProp = -1;
            int       temp        = -1;
            ArrayList propList    = new ArrayList();

            Guid[] typeGuids = new Guid[typeInfos.Length];

            for (int i = 0; i < typeInfos.Length; i++)
            {
                ITypeInfo ti = typeInfos[i];

                if (ti is null)
                {
                    continue;
                }

                uint[] versions            = new uint[2];
                Guid   typeGuid            = GetGuidForTypeInfo(ti, versions);
                PropertyDescriptor[] props = null;
                bool dontProcess           = typeGuid != Guid.Empty && processedLibraries is not null && processedLibraries.Contains(typeGuid);

                if (dontProcess)
                {
                    CachedProperties cp = (CachedProperties)processedLibraries[typeGuid];

                    if (versions[0] == cp.MajorVersion && versions[1] == cp.MinorVersion)
                    {
                        props = cp.Properties;
                        if (i == 0 && cp.DefaultIndex != -1)
                        {
                            defaultProp = cp.DefaultIndex;
                        }
                    }
                    else
                    {
                        dontProcess = false;
                    }
                }

                if (!dontProcess)
                {
                    props = InternalGetProperties(obj, ti, DispatchID.MEMBERID_NIL, ref temp);

                    // only save the default property from the first type Info
                    if (i == 0 && temp != -1)
                    {
                        defaultProp = temp;
                    }

                    if (processedLibraries is null)
                    {
                        processedLibraries = new Hashtable();
                    }

                    if (typeGuid != Guid.Empty)
                    {
                        processedLibraries[typeGuid] = new CachedProperties(props, i == 0 ? defaultProp : -1, versions[0], versions[1]);
                    }
                }

                if (props is not null)
                {
                    propList.AddRange(props);
                }
            }

            Debug.WriteLineIf(DbgTypeInfoProcessorSwitch.TraceVerbose, "Com2TypeInfoProcessor.GetProperties : returning " + propList.Count.ToString(CultureInfo.InvariantCulture) + " properties");

            // done!
            Com2PropertyDescriptor[] temp2 = new Com2PropertyDescriptor[propList.Count];
            propList.CopyTo(temp2, 0);

            return(new Com2Properties(obj, temp2, defaultProp));
        }