Exemple #1
0
 public Com2IPerPropertyBrowsingEnum(Com2PropertyDescriptor targetObject, Com2IPerPropertyBrowsingHandler handler, OleStrCAMarshaler names, Int32CAMarshaler values, bool allowUnknowns) : base(Array.Empty <string>(), Array.Empty <object>(), allowUnknowns)
 {
     target          = targetObject;
     nameMarshaller  = names;
     valueMarshaller = values;
     this.handler    = handler;
     arraysFetched   = false;
 }
Exemple #2
0
            //private bool                 standardValuesQueried;

            public Com2IPerPropertyBrowsingEnum(Com2PropertyDescriptor targetObject, Com2IPerPropertyBrowsingHandler handler, OleStrCAMarshaler names, Int32CAMarshaler values, bool allowUnknowns) : base(new string[0], new object[0], allowUnknowns)
            {
                this.target          = targetObject;
                this.nameMarshaller  = names;
                this.valueMarshaller = values;
                this.handler         = handler;
                this.arraysFetched   = false;
            }
 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);
             }
         }
     }
 }
Exemple #4
0
        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);
                    }
                }
            }
        }
 internal void UpdateTypeConverterAndTypeEditorInternal(bool force, int dispid)
 {
     if ((!this.GetFlag(1) || force) && (this.owner.GetOcx() != null))
     {
         try
         {
             System.Windows.Forms.NativeMethods.IPerPropertyBrowsing perPropertyBrowsing = this.owner.GetPerPropertyBrowsing();
             if (perPropertyBrowsing != null)
             {
                 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 = perPropertyBrowsing.GetPredefinedStrings(dispid, pCaStringsOut, pCaCookiesOut);
                 }
                 catch (ExternalException exception)
                 {
                     errorCode = exception.ErrorCode;
                 }
                 if (errorCode != 0)
                 {
                     flag = false;
                     if (this.converter is Com2EnumConverter)
                     {
                         this.converter = null;
                     }
                 }
                 else
                 {
                     flag = true;
                 }
                 if (flag)
                 {
                     OleStrCAMarshaler names = new OleStrCAMarshaler(pCaStringsOut);
                     Int32CAMarshaler values = new Int32CAMarshaler(pCaCookiesOut);
                     if ((names.Count > 0) && (values.Count > 0))
                     {
                         if (this.converter == null)
                         {
                             this.converter = new AxHost.AxEnumConverter(this, new AxHost.AxPerPropertyBrowsingEnum(this, this.owner, names, values, true));
                         }
                         else if (this.converter is AxHost.AxEnumConverter)
                         {
                             ((AxHost.AxEnumConverter) this.converter).RefreshValues();
                             AxHost.AxPerPropertyBrowsingEnum enum2 = ((AxHost.AxEnumConverter) this.converter).com2Enum as AxHost.AxPerPropertyBrowsingEnum;
                             if (enum2 != null)
                             {
                                 enum2.RefreshArrays(names, values);
                             }
                         }
                     }
                 }
                 else if (((ComAliasNameAttribute) this.baseProp.Attributes[typeof(ComAliasNameAttribute)]) == null)
                 {
                     Guid propertyPage = this.GetPropertyPage(dispid);
                     if (!Guid.Empty.Equals(propertyPage))
                     {
                         this.editor = new AxHost.AxPropertyTypeEditor(this, propertyPage);
                         if (!this.IsBrowsable)
                         {
                             this.AddAttribute(new BrowsableAttribute(true));
                         }
                     }
                 }
             }
             this.SetFlag(1, true);
         }
         catch (Exception)
         {
         }
     }
 }
 internal void RefreshArrays(OleStrCAMarshaler names, Int32CAMarshaler values)
 {
     this.nameMarshaller = names;
     this.valueMarshaller = values;
     this.arraysFetched = false;
 }
 public AxPerPropertyBrowsingEnum(AxHost.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;
 }
Exemple #8
0
            /// <devdoc>
            /// Called externally to update the editor or type converter.
            /// This simply sets flags so this will happen, it doesn't actually to the update...
            /// we wait and do that on-demand for perf.
            /// </devdoc>
            internal void UpdateTypeConverterAndTypeEditorInternal(bool force, int 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() == null) {
                    return;
                }
                    

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

                    if (ppb != null) {
                        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(dispid, caStrings, caCookies);
                        }
                        catch(ExternalException ex) {
                            hr = ex.ErrorCode;
                            Debug.Fail("An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid=" +
                                       dispid + "), object type=" + new ComNativeDescriptor().GetClassName(ppb));
                        }


                        if (hr != NativeMethods.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 == null) {
                                    converter = new AxEnumConverter(this, new AxPerPropertyBrowsingEnum(this, owner, stringMarshaler, intMarshaler, true));
                                }
                                else if (converter is AxEnumConverter){
                                    ((AxEnumConverter)converter).RefreshValues();
                                    AxPerPropertyBrowsingEnum axEnum = ((AxEnumConverter)converter).com2Enum as AxPerPropertyBrowsingEnum;
                                    if (axEnum != null) {
                                        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 == 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 (!this.IsBrowsable) {
                                       Debug.WriteLineIf(AxPropTraceSwitch.TraceVerbose, "Making property: " + this.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: " + this.Name + " Exception: " + e);
                 }
            }
     //private bool                 standardValuesQueried;
 
     public Com2IPerPropertyBrowsingEnum(Com2PropertyDescriptor targetObject, Com2IPerPropertyBrowsingHandler handler, OleStrCAMarshaler names, Int32CAMarshaler values, bool allowUnknowns) : base(new string[0], new object[0], allowUnknowns) {
        this.target = targetObject;
        this.nameMarshaller = names;
        this.valueMarshaller = values;
        this.handler = handler;
        this.arraysFetched = false;
     }
        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 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);
             }
         }
     }
 }