Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / WinForms / Managed / System / WinForms / DropTarget.cs / 1 / 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. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridViewDataErrorEventArgs.cs
- ExpressionBuilder.cs
- ErrorWebPart.cs
- AdornerLayer.cs
- ComponentChangedEvent.cs
- StorageBasedPackageProperties.cs
- HttpCacheVaryByContentEncodings.cs
- SharedStatics.cs
- Guid.cs
- SeverityFilter.cs
- ConsoleKeyInfo.cs
- RemotingSurrogateSelector.cs
- Guid.cs
- UserControl.cs
- CacheSection.cs
- VariableBinder.cs
- Rect.cs
- Hashtable.cs
- ControlParser.cs
- ReservationNotFoundException.cs
- DataGridViewSelectedCellCollection.cs
- DataServiceHostFactory.cs
- Adorner.cs
- WebServiceTypeData.cs
- CollectionChange.cs
- PriorityBinding.cs
- CommandID.cs
- DataGridViewSelectedColumnCollection.cs
- FileDialogCustomPlacesCollection.cs
- CapabilitiesUse.cs
- Point4D.cs
- RepeatBehaviorConverter.cs
- DispatcherHookEventArgs.cs
- QueueException.cs
- CommonGetThemePartSize.cs
- RuntimeHandles.cs
- AssemblyNameProxy.cs
- IssuanceLicense.cs
- MdiWindowListItemConverter.cs
- SchemaImporterExtensionElement.cs
- DependentList.cs
- DesignOnlyAttribute.cs
- ObjectQueryExecutionPlan.cs
- EntityTypeEmitter.cs
- SoapSchemaMember.cs
- XmlObjectSerializer.cs
- DoubleKeyFrameCollection.cs
- ListDictionary.cs
- BadImageFormatException.cs
- SqlUserDefinedTypeAttribute.cs
- BoolExpression.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- CookieProtection.cs
- RelationalExpressions.cs
- NCryptSafeHandles.cs
- ProfileProvider.cs
- DataGridHeaderBorder.cs
- XmlSchemaInfo.cs
- WebSysDescriptionAttribute.cs
- LinqMaximalSubtreeNominator.cs
- HMACRIPEMD160.cs
- HttpResponse.cs
- _NetworkingPerfCounters.cs
- codemethodreferenceexpression.cs
- FontNameEditor.cs
- ScopeCompiler.cs
- Claim.cs
- SecurityKeyType.cs
- SqlBooleanMismatchVisitor.cs
- DataGridViewImageCell.cs
- FieldTemplateUserControl.cs
- DataGridRowHeaderAutomationPeer.cs
- BitConverter.cs
- TabControlEvent.cs
- BasicCellRelation.cs
- NativeMethods.cs
- BinaryWriter.cs
- BasicKeyConstraint.cs
- Errors.cs
- InvokeCompletedEventArgs.cs
- TransformGroup.cs
- FixedStringLookup.cs
- Content.cs
- Row.cs
- RuntimeResourceSet.cs
- Matrix3DConverter.cs
- XPathBuilder.cs
- SwitchLevelAttribute.cs
- ProgressBarRenderer.cs
- ToolStripGripRenderEventArgs.cs
- MULTI_QI.cs
- HttpCapabilitiesBase.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- IdentityReference.cs
- ChangePassword.cs
- NumberSubstitution.cs
- BuildProviderCollection.cs
- DataIdProcessor.cs
- TakeQueryOptionExpression.cs
- WaitHandleCannotBeOpenedException.cs