Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / DesignerContextDescriptor.cs / 1 / DesignerContextDescriptor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Windows.Forms.Design {
using System;
using System.Design;
using System.ComponentModel;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms.Design.Behavior;
using System.Drawing.Design;
using System.Diagnostics;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
///
///
// ---------------------------------------------------------------------------------
// Class Implemented for opening the ImageEditor ...
//
// This class is replaces the ContextDescriptor in ToolStripItem designer.
//
// DesignerContextDescriptor implements the IWindowsFormsEditorService which is required
// to open the ImageEditor .. Hence the need for this Implementation
//-----------------------------------------------------------------------------------
///
internal class DesignerContextDescriptor : IWindowsFormsEditorService, ITypeDescriptorContext
{
private Component _component;
private PropertyDescriptor _propertyDescriptor;
private IDesignerHost _host;
//
// Constructor
//
///
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public DesignerContextDescriptor(Component component, PropertyDescriptor imageProperty, IDesignerHost host)
{
_component = component;
_propertyDescriptor = imageProperty;
_host = host;
}
///
///
/// Gets called thru the TemplateNode to open the ImageEditor.
///
///
// Called through reflection
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public Image OpenImageCollection()
{
object propertyValue = _propertyDescriptor.GetValue(_component);
if (_propertyDescriptor != null) {
Image image = null;
UITypeEditor itemsEditor = _propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
Debug.Assert(itemsEditor != null, "Didn't get a collection editor for type '" + _propertyDescriptor.PropertyType.FullName + "'");
if (itemsEditor != null) {
image = (Image)itemsEditor.EditValue(this, (IServiceProvider)this, propertyValue);
}
if (image != null) {
return image;
}
}
// Always Return old Image if Image is not changed...
return (Image)propertyValue;
}
IContainer ITypeDescriptorContext.Container {
get {
return null;
}
}
object ITypeDescriptorContext.Instance {
get {
return _component;
}
}
PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor {
get {
return _propertyDescriptor;
}
}
void ITypeDescriptorContext.OnComponentChanged() {
}
bool ITypeDescriptorContext.OnComponentChanging() {
return false;
}
///
/// Self-explanitory interface impl.
///
object IServiceProvider.GetService(Type serviceType)
{
if (serviceType == typeof(IWindowsFormsEditorService)) {
return this;
}
else {
return _host.GetService(serviceType);
}
}
///
/// Self-explanitory interface impl.
///
void IWindowsFormsEditorService.CloseDropDown()
{
// we'll never be called to do this.
//
Debug.Fail("NOTIMPL");
return;
}
///
/// Self-explanitory interface impl.
///
void IWindowsFormsEditorService.DropDownControl(Control control)
{
// nope, sorry
//
Debug.Fail("NOTIMPL");
return;
}
///
/// Self-explanitory interface impl.
///
System.Windows.Forms.DialogResult IWindowsFormsEditorService.ShowDialog(Form dialog)
{
IntPtr priorFocus = UnsafeNativeMethods.GetFocus();
DialogResult result;
IUIService uiSvc = (IUIService)((IServiceProvider)this).GetService(typeof(IUIService));
if (uiSvc != null) {
result = uiSvc.ShowDialog(dialog);
}
else {
result = dialog.ShowDialog(_component as IWin32Window);
}
if (priorFocus != IntPtr.Zero) {
UnsafeNativeMethods.SetFocus(new HandleRef(null, priorFocus));
}
return result;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- sqlcontext.cs
- XmlSchemaObjectTable.cs
- EntityProxyFactory.cs
- QuaternionIndependentAnimationStorage.cs
- RegexCompiler.cs
- WCFBuildProvider.cs
- CacheDependency.cs
- PrivateFontCollection.cs
- ColorTranslator.cs
- ToolboxItem.cs
- JapaneseCalendar.cs
- DataServiceException.cs
- DataControlImageButton.cs
- DataMemberFieldConverter.cs
- FullTextLine.cs
- InternalCache.cs
- RayMeshGeometry3DHitTestResult.cs
- WebPartCloseVerb.cs
- BinaryUtilClasses.cs
- HtmlTable.cs
- DesignerForm.cs
- CompositeFontInfo.cs
- ActivityAction.cs
- WebBrowserNavigatedEventHandler.cs
- DesignerView.Commands.cs
- ExpressionTable.cs
- WindowsIPAddress.cs
- Section.cs
- WbemException.cs
- ChannelServices.cs
- CodeExporter.cs
- DesignerEventService.cs
- WebBrowserDocumentCompletedEventHandler.cs
- ObjectDataSourceEventArgs.cs
- StylusButtonCollection.cs
- CurrentChangingEventArgs.cs
- ChangeBlockUndoRecord.cs
- DbProviderManifest.cs
- ClientTargetCollection.cs
- BaseDataList.cs
- EdmError.cs
- RadioButtonAutomationPeer.cs
- ProfileService.cs
- EntityModelBuildProvider.cs
- AssemblyBuilder.cs
- DesignerToolboxInfo.cs
- ObjectStateManager.cs
- ModelItemImpl.cs
- DesignTimeData.cs
- SortAction.cs
- IApplicationTrustManager.cs
- SecurityContextSecurityTokenAuthenticator.cs
- EntityWithChangeTrackerStrategy.cs
- SQLInt16.cs
- HtmlControlPersistable.cs
- AffineTransform3D.cs
- TrackingAnnotationCollection.cs
- JournalEntryListConverter.cs
- ViewStateException.cs
- ReliableChannelBinder.cs
- ChildrenQuery.cs
- sqlser.cs
- DictionaryBase.cs
- UnmanagedMarshal.cs
- HttpCapabilitiesBase.cs
- XmlAttributeCollection.cs
- CommonProperties.cs
- TransformProviderWrapper.cs
- AdjustableArrowCap.cs
- ColumnResult.cs
- WindowsEditBox.cs
- AccessText.cs
- DnsCache.cs
- PolyBezierSegmentFigureLogic.cs
- UiaCoreApi.cs
- HtmlControl.cs
- RegexWorker.cs
- URLIdentityPermission.cs
- HtmlControlPersistable.cs
- TypedElement.cs
- StylusPointPropertyUnit.cs
- HuffModule.cs
- ConfigurationValues.cs
- RequestSecurityToken.cs
- CharacterString.cs
- DateTimeEditor.cs
- XmlCustomFormatter.cs
- BrowserCapabilitiesFactory.cs
- MouseEvent.cs
- ErrorFormatterPage.cs
- WinInetCache.cs
- RewritingValidator.cs
- TokenFactoryBase.cs
- GiveFeedbackEvent.cs
- BaseTreeIterator.cs
- ItemMap.cs
- ResponseBodyWriter.cs
- SmiMetaDataProperty.cs
- HighContrastHelper.cs
- UIAgentAsyncEndRequest.cs