private object[] GetDraggingObjects(IDataObject dataObj, bool topLevelOnly) { object[] components = null; if (dataObj is ComponentDataObjectWrapper) { dataObj = ((ComponentDataObjectWrapper)dataObj).InnerData; ComponentDataObject cdo = (ComponentDataObject)dataObj; components = cdo.Components; } if (!topLevelOnly || components == null) { return(components); } return(GetTopLevelComponents(components)); }
public void DoOleDragDrop(DragEventArgs de) { // ASURT 43757: By the time we come here, it means that the user completed the drag-drop and // we compute the new location/size of the controls if needed and set the property values. // We have to stop freezePainting right here, so that controls can get a chance to validate // their new rects. // freezePainting = false; if (selectionHandler == null) { Debug.Fail("selectionHandler should not be null"); de.Effect = DragDropEffects.None; return; } // make sure we've actually moved if ((localDrag && de.X == dragBase.X && de.Y == dragBase.Y) || de.AllowedEffect == DragDropEffects.None || (!localDrag && !dragOk)) { de.Effect = DragDropEffects.None; return; } bool localMoveOnly = ((int)de.AllowedEffect & AllowLocalMoveOnly) != 0 && localDragInside; // if we are dragging inside the local dropsource/target, and and AllowLocalMoveOnly flag is set, // we just consider this a normal move. // bool moveAllowed = (de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None || localMoveOnly; bool copyAllowed = (de.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.None; if ((de.Effect & DragDropEffects.Move) != 0 && !moveAllowed) { // Try copy instead? de.Effect = DragDropEffects.Copy; } // make sure the copy is allowed if ((de.Effect & DragDropEffects.Copy) != 0 && !copyAllowed) { // if copy isn't allowed, don't do anything de.Effect = DragDropEffects.None; return; } if (localMoveOnly && (de.Effect & DragDropEffects.Move) != 0) { de.Effect |= (DragDropEffects)AllowLocalMoveOnly | DragDropEffects.Move; } else if ((de.Effect & DragDropEffects.Copy) != 0) { de.Effect = DragDropEffects.Copy; } if (forceDrawFrames || localDragInside) { // undraw the drag rect localDragOffset = DrawDragFrames(dragComps, localDragOffset, localDragEffect, Point.Empty, DragDropEffects.None, forceDrawFrames); forceDrawFrames = false; } Cursor oldCursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; if (dragOk || (localDragInside && de.Effect == DragDropEffects.Copy)) { // add em to this parent. IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); IContainer container = host.RootComponent.Site.Container; object[] components; IDataObject dataObj = de.Data; bool updateLocation = false; if (dataObj is ComponentDataObjectWrapper) { dataObj = ((ComponentDataObjectWrapper)dataObj).InnerData; ComponentDataObject cdo = (ComponentDataObject)dataObj; // if we're moving ot a different container, do a full serialization // to make sure we pick up design time props, etc. // IComponent dragOwner = GetDragOwnerComponent(de.Data); bool newContainer = dragOwner == null || client.Component == null || dragOwner.Site.Container != client.Component.Site.Container; bool collapseChildren = false; if (de.Effect == DragDropEffects.Copy || newContainer) { // this causes new elements to be created // cdo.Deserialize(serviceProvider, (de.Effect & DragDropEffects.Copy) == 0); } else { collapseChildren = true; } updateLocation = true; components = cdo.Components; if (collapseChildren) { components = GetTopLevelComponents(components); } } else { object serializationData = dataObj.GetData(DataFormat, true); if (serializationData == null) { Debug.Fail("data object didn't return any data, so how did we allow the drop?"); components = Array.Empty <IComponent>(); } else { dataObj = new ComponentDataObject(client, serviceProvider, serializationData); components = ((ComponentDataObject)dataObj).Components; updateLocation = true; } } // now we need to offset the components locations from the drop mouse // point to the parent, since their current locations are relative // the the mouse pointer if (components != null && components.Length > 0) { Debug.Assert(container != null, "Didn't get a container from the site!"); string name; IComponent comp = null; DesignerTransaction trans = null; try { trans = host.CreateTransaction(SR.DragDropDropComponents); if (!localDrag) { host.Activate(); } ArrayList selectComps = new ArrayList(); for (int i = 0; i < components.Length; i++) { comp = components[i] as IComponent; if (comp == null) { comp = null; continue; } try { name = null; if (comp.Site != null) { name = comp.Site.Name; } Control oldDesignerControl = null; if (updateLocation) { oldDesignerControl = client.GetDesignerControl(); User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW); } Point dropPt = client.GetDesignerControl().PointToClient(new Point(de.X, de.Y)); // First check if the component we are dropping have a TrayLocation, and if so, use it PropertyDescriptor loc = TypeDescriptor.GetProperties(comp)["TrayLocation"]; if (loc == null) { // it didn't, so let's check for the regular Location loc = TypeDescriptor.GetProperties(comp)["Location"]; } if (loc != null && !loc.IsReadOnly) { Rectangle bounds = new Rectangle(); Point pt = (Point)loc.GetValue(comp); bounds.X = dropPt.X + pt.X; bounds.Y = dropPt.Y + pt.Y; bounds = selectionHandler.GetUpdatedRect(Rectangle.Empty, bounds, false); } if (!client.AddComponent(comp, name, false)) { // this means that we just moved the control // around in the same designer. de.Effect = DragDropEffects.None; } else { // make sure the component was added to this client if (client.GetControlForComponent(comp) == null) { updateLocation = false; } } if (updateLocation) { ParentControlDesigner parentDesigner = client as ParentControlDesigner; if (parentDesigner != null) { Control c = client.GetControlForComponent(comp); dropPt = parentDesigner.GetSnappedPoint(c.Location); c.Location = dropPt; } } if (oldDesignerControl != null) { //((ComponentDataObject)dataObj).ShowControls(); User32.SendMessageW(oldDesignerControl.Handle, User32.WM.SETREDRAW, (IntPtr)1); oldDesignerControl.Invalidate(true); } if (TypeDescriptor.GetAttributes(comp).Contains(DesignTimeVisibleAttribute.Yes)) { selectComps.Add(comp); } } catch (CheckoutException ceex) { if (ceex == CheckoutException.Canceled) { break; } throw; } } if (host != null) { host.Activate(); } // select the newly added components ISelectionService selService = (ISelectionService)GetService(typeof(ISelectionService)); selService.SetSelectedComponents((object[])selectComps.ToArray(typeof(IComponent)), SelectionTypes.Replace); localDragInside = false; } finally { if (trans != null) { trans.Commit(); } } } } if (localDragInside) { ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService)); Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control"); if (selectionUISvc != null) { // We must check to ensure that UI service is still in drag mode. It is // possible that the user hit escape, which will cancel drag mode. // if (selectionUISvc.Dragging && moveAllowed) { Rectangle offset = new Rectangle(de.X - dragBase.X, de.Y - dragBase.Y, 0, 0); selectionUISvc.DragMoved(offset); } } } dragOk = false; } finally { Cursor.Current = oldCursor; } }
public ComponentDataObjectWrapper(ComponentDataObject dataObject) : base(dataObject) { throw new NotImplementedException(SR.NotImplementedByDesign); }
public ComponentDataObjectWrapper(ComponentDataObject dataObject) : base(dataObject) { innerData = dataObject; }
public void DoOleDragDrop(DragEventArgs de) { freezePainting = false; if (this.selectionHandler == null) { de.Effect = DragDropEffects.None; } else if (((this.localDrag && (de.X == this.dragBase.X)) && (de.Y == this.dragBase.Y)) || ((de.AllowedEffect == DragDropEffects.None) || (!this.localDrag && !this.dragOk))) { de.Effect = DragDropEffects.None; } else { bool flag = ((de.AllowedEffect & 0x4000000) != DragDropEffects.None) && this.localDragInside; bool flag2 = ((de.AllowedEffect & DragDropEffects.Move) != DragDropEffects.None) || flag; bool flag3 = (de.AllowedEffect & DragDropEffects.Copy) != DragDropEffects.None; if (((de.Effect & DragDropEffects.Move) != DragDropEffects.None) && !flag2) { de.Effect = DragDropEffects.Copy; } if (((de.Effect & DragDropEffects.Copy) != DragDropEffects.None) && !flag3) { de.Effect = DragDropEffects.None; } else { if (flag && ((de.Effect & DragDropEffects.Move) != DragDropEffects.None)) { de.Effect |= 0x4000002; } else if ((de.Effect & DragDropEffects.Copy) != DragDropEffects.None) { de.Effect = DragDropEffects.Copy; } if (this.forceDrawFrames || this.localDragInside) { this.localDragOffset = this.DrawDragFrames(this.dragComps, this.localDragOffset, this.localDragEffect, Point.Empty, DragDropEffects.None, this.forceDrawFrames); this.forceDrawFrames = false; } Cursor current = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; if (this.dragOk || (this.localDragInside && (de.Effect == DragDropEffects.Copy))) { object[] components; IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost)); IContainer container = service.RootComponent.Site.Container; IDataObject data = de.Data; bool flag4 = false; if (data is ComponentDataObjectWrapper) { ComponentDataObject innerData = ((ComponentDataObjectWrapper) data).InnerData; IComponent dragOwnerComponent = this.GetDragOwnerComponent(de.Data); bool flag5 = ((dragOwnerComponent == null) || (this.client.Component == null)) || (dragOwnerComponent.Site.Container != this.client.Component.Site.Container); bool flag6 = false; if ((de.Effect == DragDropEffects.Copy) || flag5) { innerData.Deserialize(this.serviceProvider, (de.Effect & DragDropEffects.Copy) == DragDropEffects.None); } else { flag6 = true; } flag4 = true; components = innerData.Components; if (flag6) { components = this.GetTopLevelComponents(components); } } else { object serializationData = data.GetData(DataFormat, true); if (serializationData == null) { components = new IComponent[0]; } else { data = new ComponentDataObject(this.client, this.serviceProvider, serializationData); components = ((ComponentDataObject) data).Components; flag4 = true; } } if ((components != null) && (components.Length > 0)) { IComponent component = null; DesignerTransaction transaction = null; try { transaction = service.CreateTransaction(System.Design.SR.GetString("DragDropDropComponents")); if (!this.localDrag) { service.Activate(); } ArrayList list = new ArrayList(); for (int i = 0; i < components.Length; i++) { component = components[i] as IComponent; if (component == null) { component = null; } else { try { string name = null; if (component.Site != null) { name = component.Site.Name; } Control designerControl = null; if (flag4) { designerControl = this.client.GetDesignerControl(); System.Design.NativeMethods.SendMessage(designerControl.Handle, 11, 0, 0); } Point snappedPoint = this.client.GetDesignerControl().PointToClient(new Point(de.X, de.Y)); PropertyDescriptor descriptor = TypeDescriptor.GetProperties(component)["TrayLocation"]; if (descriptor == null) { descriptor = TypeDescriptor.GetProperties(component)["Location"]; } if ((descriptor != null) && !descriptor.IsReadOnly) { Rectangle dragRect = new Rectangle(); Point point2 = (Point) descriptor.GetValue(component); dragRect.X = snappedPoint.X + point2.X; dragRect.Y = snappedPoint.Y + point2.Y; dragRect = this.selectionHandler.GetUpdatedRect(Rectangle.Empty, dragRect, false); } if (!this.client.AddComponent(component, name, false)) { de.Effect = DragDropEffects.None; } else if (this.client.GetControlForComponent(component) == null) { flag4 = false; } if (flag4) { ParentControlDesigner client = this.client as ParentControlDesigner; if (client != null) { Control controlForComponent = this.client.GetControlForComponent(component); snappedPoint = client.GetSnappedPoint(controlForComponent.Location); controlForComponent.Location = snappedPoint; } } if (designerControl != null) { System.Design.NativeMethods.SendMessage(designerControl.Handle, 11, 1, 0); designerControl.Invalidate(true); } if (TypeDescriptor.GetAttributes(component).Contains(DesignTimeVisibleAttribute.Yes)) { list.Add(component); } } catch (CheckoutException exception) { if (exception != CheckoutException.Canceled) { throw; } break; } } } if (service != null) { service.Activate(); } ((ISelectionService) this.GetService(typeof(ISelectionService))).SetSelectedComponents((object[]) list.ToArray(typeof(IComponent)), SelectionTypes.Replace); this.localDragInside = false; } finally { if (transaction != null) { transaction.Commit(); } } } } if (this.localDragInside) { ISelectionUIService service2 = (ISelectionUIService) this.GetService(typeof(ISelectionUIService)); if (((service2 != null) && service2.Dragging) && flag2) { Rectangle offset = new Rectangle(de.X - this.dragBase.X, de.Y - this.dragBase.Y, 0, 0); service2.DragMoved(offset); } } this.dragOk = false; } finally { Cursor.Current = current; } } } }