Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2IProvidePropertyBuilderHandler.cs / 1 / COM2IProvidePropertyBuilderHandler.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.ComponentModel.Com2Interop {
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Collections;
using Microsoft.Win32;
using System.Drawing.Design;
[System.Security.SuppressUnmanagedCodeSecurityAttribute()]
internal class Com2IProvidePropertyBuilderHandler : Com2ExtendedBrowsingHandler {
public override Type Interface {
get {
return typeof(NativeMethods.IProvidePropertyBuilder);
}
}
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;
}
public override void SetupPropertyHandlers(Com2PropertyDescriptor[] propDesc) {
if (propDesc == null) {
return;
}
for (int i = 0; i < propDesc.Length; i++) {
propDesc[i].QueryGetBaseAttributes += new GetAttributesEventHandler(this.OnGetBaseAttributes);
propDesc[i].QueryGetTypeConverterAndTypeEditor += new GetTypeConverterAndTypeEditorEventHandler(this.OnGetTypeConverterAndTypeEditor);
}
}
///
///
/// Here is where we handle IVsPerPropertyBrowsing.GetLocalizedPropertyInfo and IVsPerPropertyBrowsing. HideProperty
/// such as IPerPropertyBrowsing, IProvidePropertyBuilder, etc.
///
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);
}
}
}
}
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);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.ComponentModel.Com2Interop {
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Collections;
using Microsoft.Win32;
using System.Drawing.Design;
[System.Security.SuppressUnmanagedCodeSecurityAttribute()]
internal class Com2IProvidePropertyBuilderHandler : Com2ExtendedBrowsingHandler {
public override Type Interface {
get {
return typeof(NativeMethods.IProvidePropertyBuilder);
}
}
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;
}
public override void SetupPropertyHandlers(Com2PropertyDescriptor[] propDesc) {
if (propDesc == null) {
return;
}
for (int i = 0; i < propDesc.Length; i++) {
propDesc[i].QueryGetBaseAttributes += new GetAttributesEventHandler(this.OnGetBaseAttributes);
propDesc[i].QueryGetTypeConverterAndTypeEditor += new GetTypeConverterAndTypeEditorEventHandler(this.OnGetTypeConverterAndTypeEditor);
}
}
///
///
/// Here is where we handle IVsPerPropertyBrowsing.GetLocalizedPropertyInfo and IVsPerPropertyBrowsing. HideProperty
/// such as IPerPropertyBrowsing, IProvidePropertyBuilder, etc.
///
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);
}
}
}
}
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);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RadioButton.cs
- StrokeNodeData.cs
- X509ChainPolicy.cs
- SerializationSectionGroup.cs
- TextAdaptor.cs
- XPathNavigator.cs
- Rules.cs
- KeyBinding.cs
- TextCompositionEventArgs.cs
- ApplicationSecurityManager.cs
- AmbientProperties.cs
- BuildProvider.cs
- ConsumerConnectionPointCollection.cs
- TextInfo.cs
- ServiceOperation.cs
- WebConfigurationHost.cs
- PlainXmlSerializer.cs
- DesignerSerializationVisibilityAttribute.cs
- DataGridViewSelectedCellCollection.cs
- TransformConverter.cs
- TextProviderWrapper.cs
- SchemaInfo.cs
- Journaling.cs
- RecoverInstanceLocksCommand.cs
- XmlAtomicValue.cs
- Rules.cs
- GroupBox.cs
- DataListItemEventArgs.cs
- MultipleViewPattern.cs
- ClaimTypeRequirement.cs
- FixedSOMPageElement.cs
- Clause.cs
- DiscoveryRequestHandler.cs
- XmlSchemaElement.cs
- DragStartedEventArgs.cs
- SoapHeaders.cs
- StylusPointPropertyUnit.cs
- MessageFilterException.cs
- LambdaCompiler.cs
- DoubleCollectionValueSerializer.cs
- AttributeCollection.cs
- DataPagerFieldItem.cs
- AppSecurityManager.cs
- SQLDouble.cs
- RequestCacheManager.cs
- DrawingContextDrawingContextWalker.cs
- DispatcherOperation.cs
- FilterQuery.cs
- DbProviderSpecificTypePropertyAttribute.cs
- LocalizeDesigner.cs
- SecurityCapabilities.cs
- EndCreateSecurityTokenRequest.cs
- SafeNativeMethods.cs
- ListViewDataItem.cs
- FamilyCollection.cs
- RegexGroupCollection.cs
- BufferAllocator.cs
- EdmFunction.cs
- DataGridViewComboBoxCell.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- ResourcesGenerator.cs
- XmlSerializerSection.cs
- RootBrowserWindow.cs
- ScriptResourceDefinition.cs
- AdPostCacheSubstitution.cs
- InternalBase.cs
- ForceCopyBuildProvider.cs
- Cell.cs
- LocalizableAttribute.cs
- ImageConverter.cs
- BinaryFormatterWriter.cs
- EventLogRecord.cs
- TransformConverter.cs
- BackoffTimeoutHelper.cs
- ObjectContext.cs
- EdmType.cs
- ControlCachePolicy.cs
- ForeignConstraint.cs
- XpsStructure.cs
- TextOptions.cs
- EventLogPermission.cs
- ZipIOFileItemStream.cs
- ContentFilePart.cs
- OdbcInfoMessageEvent.cs
- MsmqChannelFactoryBase.cs
- TraceData.cs
- ComAdminInterfaces.cs
- KeySpline.cs
- RangeEnumerable.cs
- Rfc2898DeriveBytes.cs
- XmlSchemas.cs
- PixelFormats.cs
- DataFormat.cs
- PackageRelationship.cs
- HostUtils.cs
- DetailsView.cs
- XmlSchemaAttributeGroupRef.cs
- SerializationStore.cs
- FixUp.cs
- HandlerBase.cs