Esempio n. 1
0
 public override void OnDragDrop(Glyph g, DragEventArgs e)
 {
     this.behaviorService.PopBehavior(this);
     try
     {
         Point point = this.behaviorService.AdornerWindowToScreen();
         ToolboxSnapDragDropEventArgs args = this.CreateToolboxSnapArgs(e, new Point(e.X - point.X, e.Y - point.Y));
         base.OnDragDrop(g, args);
     }
     finally
     {
         this.IsPushed = false;
     }
 }
        /// <summary>
        ///  OnDragDrop can be overridden so that a Behavior can specify its own
        ///  Drag/Drop rules.
        /// </summary>
        public override void OnDragDrop(Glyph g, DragEventArgs e)
        {
            behaviorService.PopBehavior(this);

            try
            {
                //offset the mouse loc to screen coords for calculations on drops
                Point screenOffset = behaviorService.AdornerWindowToScreen();

                //build up our extra-special event args
                ToolboxSnapDragDropEventArgs se = CreateToolboxSnapArgs(e, new Point(e.X - screenOffset.X, e.Y - screenOffset.Y));

                base.OnDragDrop(g, se);
            }
            finally
            {
                //clear everything up
                IsPushed = false;
            }
        }
 public IComponent[] CreateTool(ToolboxItem tool, Control parent, int x, int y, int width, int height, bool hasLocation, bool hasSize, ToolboxSnapDragDropEventArgs e)
 {
     IToolboxService service = (IToolboxService) this.GetService(typeof(IToolboxService));
     ISelectionService service2 = (ISelectionService) this.GetService(typeof(ISelectionService));
     IDesignerHost host = (IDesignerHost) this.GetService(typeof(IDesignerHost));
     IComponent[] c = new IComponent[0];
     Cursor current = Cursor.Current;
     Cursor.Current = Cursors.WaitCursor;
     DesignerTransaction transaction = null;
     try
     {
         try
         {
             if (host != null)
             {
                 transaction = host.CreateTransaction(System.Design.SR.GetString("DesignerBatchCreateTool", new object[] { tool.ToString() }));
             }
         }
         catch (CheckoutException exception)
         {
             if (exception != CheckoutException.Canceled)
             {
                 throw exception;
             }
             return c;
         }
         try
         {
             try
             {
                 if ((host != null) && this.CurrentlyLocalizing(host.RootComponent))
                 {
                     IUIService service3 = (IUIService) this.GetService(typeof(IUIService));
                     if (service3 != null)
                     {
                         service3.ShowMessage(System.Design.SR.GetString("LocalizingCannotAdd"));
                     }
                     return new IComponent[0];
                 }
                 Hashtable defaultValues = new Hashtable();
                 if (parent != null)
                 {
                     defaultValues["Parent"] = parent;
                 }
                 if ((parent != null) && parent.IsMirrored)
                 {
                     x += width;
                 }
                 if (hasLocation)
                 {
                     defaultValues["Location"] = new Point(x, y);
                 }
                 if (hasSize)
                 {
                     defaultValues["Size"] = new Size(width, height);
                 }
                 if (e != null)
                 {
                     defaultValues["ToolboxSnapDragDropEventArgs"] = e;
                 }
                 c = tool.CreateComponents(host, defaultValues);
             }
             catch (CheckoutException exception2)
             {
                 if (exception2 != CheckoutException.Canceled)
                 {
                     throw;
                 }
                 c = new IComponent[0];
             }
             catch (ArgumentException exception3)
             {
                 IUIService service4 = (IUIService) this.GetService(typeof(IUIService));
                 if (service4 != null)
                 {
                     service4.ShowError(exception3);
                 }
             }
             catch (Exception exception4)
             {
                 IUIService service5 = (IUIService) this.GetService(typeof(IUIService));
                 string message = string.Empty;
                 if (exception4.InnerException != null)
                 {
                     message = exception4.InnerException.ToString();
                 }
                 if (string.IsNullOrEmpty(message))
                 {
                     message = exception4.ToString();
                 }
                 if (exception4 is InvalidOperationException)
                 {
                     message = exception4.Message;
                 }
                 if (service5 == null)
                 {
                     throw;
                 }
                 service5.ShowError(exception4, System.Design.SR.GetString("FailedToCreateComponent", new object[] { tool.DisplayName, message }));
             }
             if (c == null)
             {
                 c = new IComponent[0];
             }
         }
         finally
         {
             if ((service != null) && tool.Equals(service.GetSelectedToolboxItem(host)))
             {
                 service.SelectedToolboxItemUsed();
             }
         }
     }
     finally
     {
         if (transaction != null)
         {
             transaction.Commit();
         }
         Cursor.Current = current;
     }
     if ((service2 != null) && (c.Length > 0))
     {
         if (host != null)
         {
             host.Activate();
         }
         ArrayList list = new ArrayList(c);
         for (int i = 0; i < c.Length; i++)
         {
             if (!TypeDescriptor.GetAttributes(c[i]).Contains(DesignTimeVisibleAttribute.Yes))
             {
                 list.Remove(c[i]);
             }
         }
         service2.SetSelectedComponents(list.ToArray(), SelectionTypes.Replace);
     }
     codemarkers.CodeMarker(0x1d4d);
     return c;
 }
 protected override void OnDragDrop(DragEventArgs de)
 {
     if (de is ToolboxSnapDragDropEventArgs)
     {
         this.toolboxSnapDragDropEventArgs = de as ToolboxSnapDragDropEventArgs;
     }
     DropSourceBehavior.BehaviorDataObject data = de.Data as DropSourceBehavior.BehaviorDataObject;
     if (data != null)
     {
         data.Target = base.Component;
         data.EndDragDrop(this.AllowSetChildIndexOnDrop);
         this.OnDragComplete(de);
     }
     else if ((this.mouseDragTool == null) && (data == null))
     {
         OleDragDropHandler oleDragHandler = this.GetOleDragHandler();
         if (oleDragHandler != null)
         {
             IOleDragClient destination = oleDragHandler.Destination;
             if (((destination != null) && (destination.Component != null)) && (destination.Component.Site != null))
             {
                 IContainer container = destination.Component.Site.Container;
                 if (container != null)
                 {
                     object[] draggingObjects = oleDragHandler.GetDraggingObjects(de);
                     for (int i = 0; i < draggingObjects.Length; i++)
                     {
                         IComponent component = draggingObjects[i] as IComponent;
                         container.Add(component);
                     }
                 }
             }
         }
     }
     if (this.mouseDragTool != null)
     {
         IDesignerHost service = (IDesignerHost) this.GetService(typeof(IDesignerHost));
         if (service != null)
         {
             service.Activate();
         }
         try
         {
             if (base.BehaviorService != null)
             {
                 base.BehaviorService.EndDragNotification();
             }
             this.CreateTool(this.mouseDragTool, new Point(de.X, de.Y));
         }
         catch (Exception exception)
         {
             if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
             {
                 throw;
             }
             base.DisplayError(exception);
         }
         this.mouseDragTool = null;
     }
 }
 protected virtual IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
 {
     IComponent[] componentArray = null;
     try
     {
         componentArray = this.GetOleDragHandler().CreateTool(tool, this.Control, x, y, width, height, hasLocation, hasSize, this.toolboxSnapDragDropEventArgs);
     }
     finally
     {
         this.toolboxSnapDragDropEventArgs = null;
     }
     return componentArray;
 }
 public static Rectangle GetBoundsFromToolboxSnapDragDropInfo(ToolboxSnapDragDropEventArgs e, Rectangle originalBounds, bool isMirrored)
 {
     Rectangle rectangle = originalBounds;
     if (e.Offset != Point.Empty)
     {
         if ((e.SnapDirections & ToolboxSnapDragDropEventArgs.SnapDirection.Top) != ToolboxSnapDragDropEventArgs.SnapDirection.None)
         {
             rectangle.Y += e.Offset.Y;
         }
         else if ((e.SnapDirections & ToolboxSnapDragDropEventArgs.SnapDirection.Bottom) != ToolboxSnapDragDropEventArgs.SnapDirection.None)
         {
             rectangle.Y = (originalBounds.Y - originalBounds.Height) + e.Offset.Y;
         }
         if (!isMirrored)
         {
             if ((e.SnapDirections & ToolboxSnapDragDropEventArgs.SnapDirection.Left) != ToolboxSnapDragDropEventArgs.SnapDirection.None)
             {
                 rectangle.X += e.Offset.X;
                 return rectangle;
             }
             if ((e.SnapDirections & ToolboxSnapDragDropEventArgs.SnapDirection.Right) != ToolboxSnapDragDropEventArgs.SnapDirection.None)
             {
                 rectangle.X = (originalBounds.X - originalBounds.Width) + e.Offset.X;
             }
             return rectangle;
         }
         if ((e.SnapDirections & ToolboxSnapDragDropEventArgs.SnapDirection.Left) != ToolboxSnapDragDropEventArgs.SnapDirection.None)
         {
             rectangle.X = (originalBounds.X - originalBounds.Width) - e.Offset.X;
             return rectangle;
         }
         if ((e.SnapDirections & ToolboxSnapDragDropEventArgs.SnapDirection.Right) != ToolboxSnapDragDropEventArgs.SnapDirection.None)
         {
             rectangle.X -= e.Offset.X;
         }
     }
     return rectangle;
 }