Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / WinForms / Managed / System / WinForms / ComponentModel / COM2Interop / COM2PropertyPageUITypeConverter.cs / 1 / COM2PropertyPageUITypeConverter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.ComponentModel.Com2Interop {
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Design;
using System.Runtime.InteropServices;
using System.Windows.Forms.Design;
///
///
///
internal class Com2PropertyPageUITypeEditor : Com2ExtendedUITypeEditor, ICom2PropertyPageDisplayService {
private Com2PropertyDescriptor propDesc;
private Guid guid;
public Com2PropertyPageUITypeEditor(Com2PropertyDescriptor pd, Guid guid, UITypeEditor baseEditor) : base(baseEditor){
propDesc = pd;
this.guid = guid;
}
///
///
/// 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.
///
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
IntPtr hWndParent = UnsafeNativeMethods.GetFocus(); // Windows.GetForegroundWindow
try {
ICom2PropertyPageDisplayService propPageSvc = (ICom2PropertyPageDisplayService)provider.GetService(typeof(ICom2PropertyPageDisplayService));
if (propPageSvc == null) {
propPageSvc = this;
}
object instance = context.Instance;
if (!instance.GetType().IsArray) {
instance = propDesc.TargetObject;
if (instance is ICustomTypeDescriptor) {
instance = ((ICustomTypeDescriptor)instance).GetPropertyOwner(propDesc);
}
}
propPageSvc.ShowPropertyPage(propDesc.Name, instance, propDesc.DISPID, this.guid, hWndParent);
}
catch (Exception ex1) {
if (provider != null) {
IUIService uiSvc = (IUIService)provider.GetService(typeof(IUIService));
if (uiSvc != null){
uiSvc.ShowError(ex1, SR.GetString(SR.ErrorTypeConverterFailed));
}
}
}
return value;
}
///
///
/// Retrieves the editing style of the Edit method. If the method
/// is not supported, this will return None.
///
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.Modal;
}
public unsafe void ShowPropertyPage(string title, object component, int dispid, Guid pageGuid, IntPtr parentHandle){
Guid[] guids = new Guid[]{pageGuid};
IntPtr guidsAddr = Marshal.UnsafeAddrOfPinnedArrayElement(guids, 0);
object[] objs = component.GetType().IsArray ? (object[])component : new object[]{component};
int nObjs = objs.Length;
IntPtr[] objAddrs = new IntPtr[nObjs];
try {
for (int i=0; i < nObjs; i++) {
objAddrs[i] = Marshal.GetIUnknownForObject(objs[i]);
}
fixed (IntPtr* pAddrs = objAddrs) {
SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(null, parentHandle),
0, 0,
title,
nObjs,
new HandleRef(null, (IntPtr)(long)pAddrs),
1,
new HandleRef(null, guidsAddr),
SafeNativeMethods.GetThreadLCID(),
0, IntPtr.Zero );
}
} finally {
for (int i=0; i < nObjs; i++) {
if (objAddrs[i] != IntPtr.Zero) {
Marshal.Release(objAddrs[i]);
}
}
}
}
}
}
// 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 Microsoft.Win32;
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Design;
using System.Runtime.InteropServices;
using System.Windows.Forms.Design;
///
///
///
internal class Com2PropertyPageUITypeEditor : Com2ExtendedUITypeEditor, ICom2PropertyPageDisplayService {
private Com2PropertyDescriptor propDesc;
private Guid guid;
public Com2PropertyPageUITypeEditor(Com2PropertyDescriptor pd, Guid guid, UITypeEditor baseEditor) : base(baseEditor){
propDesc = pd;
this.guid = guid;
}
///
///
/// 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.
///
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
IntPtr hWndParent = UnsafeNativeMethods.GetFocus(); // Windows.GetForegroundWindow
try {
ICom2PropertyPageDisplayService propPageSvc = (ICom2PropertyPageDisplayService)provider.GetService(typeof(ICom2PropertyPageDisplayService));
if (propPageSvc == null) {
propPageSvc = this;
}
object instance = context.Instance;
if (!instance.GetType().IsArray) {
instance = propDesc.TargetObject;
if (instance is ICustomTypeDescriptor) {
instance = ((ICustomTypeDescriptor)instance).GetPropertyOwner(propDesc);
}
}
propPageSvc.ShowPropertyPage(propDesc.Name, instance, propDesc.DISPID, this.guid, hWndParent);
}
catch (Exception ex1) {
if (provider != null) {
IUIService uiSvc = (IUIService)provider.GetService(typeof(IUIService));
if (uiSvc != null){
uiSvc.ShowError(ex1, SR.GetString(SR.ErrorTypeConverterFailed));
}
}
}
return value;
}
///
///
/// Retrieves the editing style of the Edit method. If the method
/// is not supported, this will return None.
///
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.Modal;
}
public unsafe void ShowPropertyPage(string title, object component, int dispid, Guid pageGuid, IntPtr parentHandle){
Guid[] guids = new Guid[]{pageGuid};
IntPtr guidsAddr = Marshal.UnsafeAddrOfPinnedArrayElement(guids, 0);
object[] objs = component.GetType().IsArray ? (object[])component : new object[]{component};
int nObjs = objs.Length;
IntPtr[] objAddrs = new IntPtr[nObjs];
try {
for (int i=0; i < nObjs; i++) {
objAddrs[i] = Marshal.GetIUnknownForObject(objs[i]);
}
fixed (IntPtr* pAddrs = objAddrs) {
SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(null, parentHandle),
0, 0,
title,
nObjs,
new HandleRef(null, (IntPtr)(long)pAddrs),
1,
new HandleRef(null, guidsAddr),
SafeNativeMethods.GetThreadLCID(),
0, IntPtr.Zero );
}
} finally {
for (int i=0; i < nObjs; i++) {
if (objAddrs[i] != IntPtr.Zero) {
Marshal.Release(objAddrs[i]);
}
}
}
}
}
}
// 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
- SelectionEditingBehavior.cs
- RoutedEvent.cs
- TreeNodeStyleCollection.cs
- XmlElementCollection.cs
- X509Certificate2Collection.cs
- InvalidWMPVersionException.cs
- SequenceQuery.cs
- ExceptionUtility.cs
- DocobjHost.cs
- ChannelManager.cs
- ipaddressinformationcollection.cs
- Annotation.cs
- OutKeywords.cs
- GenericTextProperties.cs
- ChtmlCommandAdapter.cs
- WarningException.cs
- TileBrush.cs
- TemplateBindingExpression.cs
- HtmlInputImage.cs
- EncodingNLS.cs
- PointConverter.cs
- RsaEndpointIdentity.cs
- ServiceOperationDetailViewControl.cs
- DocumentSequenceHighlightLayer.cs
- ServiceHostFactory.cs
- ChannelAcceptor.cs
- ApplicationInfo.cs
- InvokePattern.cs
- Point.cs
- CLRBindingWorker.cs
- TextParaLineResult.cs
- TextTreeObjectNode.cs
- ZoneButton.cs
- WindowsAuthenticationEventArgs.cs
- ToolZone.cs
- SqlDataRecord.cs
- EnlistmentTraceIdentifier.cs
- DelimitedListTraceListener.cs
- TypeLoadException.cs
- QilLoop.cs
- CaseCqlBlock.cs
- IsolatedStorageException.cs
- AspProxy.cs
- PropertyEmitter.cs
- BaseAppDomainProtocolHandler.cs
- LingerOption.cs
- AnyAllSearchOperator.cs
- DetailsViewInsertEventArgs.cs
- LZCodec.cs
- ReadOnlyDataSource.cs
- AccessDataSourceView.cs
- SessionEndingEventArgs.cs
- ImageDrawing.cs
- Stylesheet.cs
- TraceContext.cs
- PeerContact.cs
- XmlDataSourceNodeDescriptor.cs
- CodeVariableDeclarationStatement.cs
- HwndSource.cs
- templategroup.cs
- XsdDateTime.cs
- WebBrowserProgressChangedEventHandler.cs
- SectionUpdates.cs
- SchemaTypeEmitter.cs
- ConditionBrowserDialog.cs
- ItemAutomationPeer.cs
- _ConnectOverlappedAsyncResult.cs
- DragStartedEventArgs.cs
- RecognizerBase.cs
- ReadWriteSpinLock.cs
- LogicalExpr.cs
- UpdateCommand.cs
- EpmSourcePathSegment.cs
- XsdDataContractExporter.cs
- BypassElementCollection.cs
- OracleConnectionString.cs
- WebPartCollection.cs
- FixedHyperLink.cs
- PassportAuthenticationModule.cs
- StrokeNodeOperations.cs
- WindowPattern.cs
- TemplateAction.cs
- CmsInterop.cs
- IPGlobalProperties.cs
- PropertyContainer.cs
- _OverlappedAsyncResult.cs
- LineGeometry.cs
- TransportDefaults.cs
- ConnectionPoint.cs
- ContextDataSourceContextData.cs
- XhtmlBasicSelectionListAdapter.cs
- VectorKeyFrameCollection.cs
- FilePresentation.cs
- Compiler.cs
- PaperSize.cs
- MouseActionConverter.cs
- DrawingContextDrawingContextWalker.cs
- FieldBuilder.cs
- CaseInsensitiveComparer.cs
- TabControlCancelEvent.cs