Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / DropTarget.cs / 1305376 / DropTarget.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System;
using System.Diagnostics;
using System.Security.Permissions;
using System.Security;
using System.ComponentModel;
using IComDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;
///
///
internal class DropTarget : UnsafeNativeMethods.IOleDropTarget {
private IDataObject lastDataObject = null;
private DragDropEffects lastEffect = DragDropEffects.None;
private IDropTarget owner;
public DropTarget(IDropTarget owner) {
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "DropTarget created");
this.owner = owner;
}
#if DEBUG
~DropTarget() {
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "DropTarget destroyed");
}
#endif
private DragEventArgs CreateDragEventArgs(object pDataObj, int grfKeyState, NativeMethods.POINTL pt, int pdwEffect) {
IDataObject data = null;
if (pDataObj == null) {
data = lastDataObject;
}
else {
if (pDataObj is IDataObject) {
data = (IDataObject)pDataObj;
}
else if (pDataObj is IComDataObject) {
data = new DataObject(pDataObj);
}
else {
return null; // Unknown data object interface; we can't work with this so return null
}
}
DragEventArgs drgevent = new DragEventArgs(data, grfKeyState, pt.x, pt.y, (DragDropEffects)pdwEffect, lastEffect);
lastDataObject = data;
return drgevent;
}
int UnsafeNativeMethods.IOleDropTarget.OleDragEnter(object pDataObj, int grfKeyState,
long pt,
ref int pdwEffect) {
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragEnter recieved");
NativeMethods.POINTL ptl = new NativeMethods.POINTL();
ptl.x = GetX(pt);
ptl.y = GetY(pt);
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "\t" + (ptl.x) + "," + (ptl.y));
Debug.Assert(pDataObj != null, "OleDragEnter didn't give us a valid data object.");
DragEventArgs drgevent = CreateDragEventArgs(pDataObj, grfKeyState, ptl, pdwEffect);
if (drgevent != null) {
owner.OnDragEnter(drgevent);
pdwEffect = (int)drgevent.Effect;
lastEffect = drgevent.Effect;
}
else {
pdwEffect = (int)DragDropEffects.None;
}
return NativeMethods.S_OK;
}
int UnsafeNativeMethods.IOleDropTarget.OleDragOver(int grfKeyState, long pt, ref int pdwEffect) {
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragOver recieved");
NativeMethods.POINTL ptl = new NativeMethods.POINTL();
ptl.x = GetX(pt);
ptl.y = GetY(pt);
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "\t" + (ptl.x) + "," + (ptl.y));
DragEventArgs drgevent = CreateDragEventArgs(null, grfKeyState, ptl, pdwEffect);
owner.OnDragOver(drgevent);
pdwEffect = (int)drgevent.Effect;
lastEffect = drgevent.Effect;
return NativeMethods.S_OK;
}
int UnsafeNativeMethods.IOleDropTarget.OleDragLeave() {
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDragLeave recieved");
owner.OnDragLeave(EventArgs.Empty);
return NativeMethods.S_OK;
}
int UnsafeNativeMethods.IOleDropTarget.OleDrop(object pDataObj, int grfKeyState, long pt, ref int pdwEffect) {
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "OleDrop recieved");
NativeMethods.POINTL ptl = new NativeMethods.POINTL();
ptl.x = GetX(pt);
ptl.y = GetY(pt);
Debug.WriteLineIf(CompModSwitches.DragDrop.TraceInfo, "\t" + (ptl.x) + "," + (ptl.y));
DragEventArgs drgevent = CreateDragEventArgs(pDataObj, grfKeyState, ptl, pdwEffect);
if (drgevent != null) {
owner.OnDragDrop(drgevent);
pdwEffect = (int)drgevent.Effect;
}
else {
pdwEffect = (int)DragDropEffects.None;
}
lastEffect = DragDropEffects.None;
lastDataObject = null;
return NativeMethods.S_OK;
}
private int GetX(long pt) {
return(int)(pt & 0xFFFFFFFF);
}
private int GetY(long pt) {
return(int)((pt >> 32) & 0xFFFFFFFF);
}
}
}
// 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
- CodeNamespace.cs
- ClientTargetSection.cs
- EngineSiteSapi.cs
- DetailsViewInsertEventArgs.cs
- SerializationFieldInfo.cs
- CatalogPartCollection.cs
- ToolStripSeparator.cs
- ObjectItemCachedAssemblyLoader.cs
- ScriptManagerProxy.cs
- SkipQueryOptionExpression.cs
- Membership.cs
- PatternMatcher.cs
- CheckoutException.cs
- WebResourceAttribute.cs
- ErrorHandler.cs
- HttpModulesSection.cs
- DefaultValueTypeConverter.cs
- MimeTypeAttribute.cs
- coordinatorfactory.cs
- SystemNetworkInterface.cs
- SelectedDatesCollection.cs
- MsmqIntegrationBindingElement.cs
- LoadedOrUnloadedOperation.cs
- MatrixTransform3D.cs
- Line.cs
- BitmapCache.cs
- ObjectListDataBindEventArgs.cs
- StringAttributeCollection.cs
- SecurityResources.cs
- ScriptResourceInfo.cs
- ConfigurationConverterBase.cs
- EnterpriseServicesHelper.cs
- Region.cs
- Util.cs
- XmlDownloadManager.cs
- AssociationSetMetadata.cs
- TableAutomationPeer.cs
- ReadOnlyDataSourceView.cs
- RegionData.cs
- CreateUserErrorEventArgs.cs
- SynchronizedDisposablePool.cs
- EncoderFallback.cs
- MessageAction.cs
- ColumnMapCopier.cs
- OracleConnection.cs
- EmptyStringExpandableObjectConverter.cs
- ActiveXSite.cs
- CompilerGeneratedAttribute.cs
- InvalidWMPVersionException.cs
- Connection.cs
- MediaContext.cs
- SqlConnectionPoolGroupProviderInfo.cs
- SQLSingleStorage.cs
- Opcode.cs
- LineSegment.cs
- SafeSecurityHelper.cs
- MaterializeFromAtom.cs
- MulticastIPAddressInformationCollection.cs
- Substitution.cs
- ProxyElement.cs
- BitmapEffectInputConnector.cs
- RuleSettingsCollection.cs
- RecipientServiceModelSecurityTokenRequirement.cs
- DeleteMemberBinder.cs
- EndpointAddressAugust2004.cs
- TemplateApplicationHelper.cs
- DispatchChannelSink.cs
- RowSpanVector.cs
- Odbc32.cs
- Variant.cs
- EmptyStringExpandableObjectConverter.cs
- RoutingConfiguration.cs
- SByteConverter.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- ReadOnlyCollectionBase.cs
- SqlNotificationRequest.cs
- StructuredTypeEmitter.cs
- ColorConverter.cs
- TimeSpanValidatorAttribute.cs
- ConnectionPointCookie.cs
- UnaryExpression.cs
- Int64KeyFrameCollection.cs
- XmlMtomReader.cs
- Double.cs
- Scheduler.cs
- WebConfigurationHostFileChange.cs
- TimelineGroup.cs
- ErrorFormatter.cs
- ProxyWebPartConnectionCollection.cs
- ActivityCollectionMarkupSerializer.cs
- SoapClientMessage.cs
- SQLStringStorage.cs
- HyperLinkDataBindingHandler.cs
- XPathEmptyIterator.cs
- DPCustomTypeDescriptor.cs
- Predicate.cs
- BindingCollection.cs
- PathSegment.cs
- DesigntimeLicenseContext.cs
- BitmapEncoder.cs