Example #1
0
        private ToolboxSnapDragDropEventArgs CreateToolboxSnapArgs(DragEventArgs e, Point mouseLoc)
        {
            ToolboxSnapDragDropEventArgs.SnapDirection none = ToolboxSnapDragDropEventArgs.SnapDirection.None;
            Point empty = Point.Empty;
            bool  flag  = false;
            bool  flag2 = false;

            if (this.dragManager != null)
            {
                foreach (DragAssistanceManager.Line line in this.dragManager.GetRecentLines())
                {
                    if (line.LineType == DragAssistanceManager.LineType.Standard)
                    {
                        if (!flag && (line.x1 == line.x2))
                        {
                            if (line.x1 == this.lastRectangle.Left)
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Left;
                                empty.X = this.lastRectangle.Left - mouseLoc.X;
                            }
                            else
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Right;
                                empty.X = this.lastRectangle.Right - mouseLoc.X;
                            }
                            flag = true;
                        }
                        else if (!flag2 && (line.y1 == line.y2))
                        {
                            if (line.y1 == this.lastRectangle.Top)
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Top;
                                empty.Y = this.lastRectangle.Top - mouseLoc.Y;
                            }
                            else if (line.y1 == this.lastRectangle.Bottom)
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Bottom;
                                empty.Y = this.lastRectangle.Bottom - mouseLoc.Y;
                            }
                            flag2 = true;
                        }
                    }
                    else if ((line.LineType == DragAssistanceManager.LineType.Margin) || (line.LineType == DragAssistanceManager.LineType.Padding))
                    {
                        if (!flag2 && (line.x1 == line.x2))
                        {
                            if (Math.Max(line.y1, line.y2) <= this.lastRectangle.Top)
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Top;
                                empty.Y = this.lastRectangle.Top - mouseLoc.Y;
                            }
                            else
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Bottom;
                                empty.Y = this.lastRectangle.Bottom - mouseLoc.Y;
                            }
                            flag2 = true;
                        }
                        else if (!flag && (line.y1 == line.y2))
                        {
                            if (Math.Max(line.x1, line.x2) <= this.lastRectangle.Left)
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Left;
                                empty.X = this.lastRectangle.Left - mouseLoc.X;
                            }
                            else
                            {
                                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Right;
                                empty.X = this.lastRectangle.Right - mouseLoc.X;
                            }
                            flag = true;
                        }
                    }
                    if (flag && flag2)
                    {
                        break;
                    }
                }
            }
            if (!flag)
            {
                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Left;
                empty.X = this.lastRectangle.Left - mouseLoc.X;
            }
            if (!flag2)
            {
                none   |= ToolboxSnapDragDropEventArgs.SnapDirection.Top;
                empty.Y = this.lastRectangle.Top - mouseLoc.Y;
            }
            return(new ToolboxSnapDragDropEventArgs(none, empty, e));
        }
        /// <summary>
        ///  Called on a DragDrop - this generates our extra drag info
        ///  to pass along to the base class.  Basically, we get the
        ///  last-rendered snaplines before the drop and attempt to
        ///  identify to which direction the mouse was snapped.
        /// </summary>
        private ToolboxSnapDragDropEventArgs CreateToolboxSnapArgs(DragEventArgs e, Point mouseLoc)
        {
            //we're trying to set these two vars here...
            ToolboxSnapDragDropEventArgs.SnapDirection snapDirections = ToolboxSnapDragDropEventArgs.SnapDirection.None;
            Point offset = Point.Empty;

            //as soon as these vars are true - we can stop looking at lines
            bool horizontalComponentIdentified = false;
            bool verticalComponentIdentified   = false;

            if (dragManager != null)
            {
                DragAssistanceManager.Line[] lines = dragManager.GetRecentLines();

                foreach (DragAssistanceManager.Line line in lines)
                {
                    if (line.LineType == DragAssistanceManager.LineType.Standard)
                    {
                        if (!horizontalComponentIdentified && line.x1 == line.x2)
                        {
                            //check for vertical equality
                            if (line.x1 == lastRectangle.Left)
                            {
                                //we had a line on the left of the box - so we must have snapped left
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Left;
                                offset.X        = lastRectangle.Left - mouseLoc.X;
                            }
                            else
                            {//MUST BE RIGHT?  if (lines.x1 == lastRectangle.Right) {
                             //we had a line on the right of the box - so we must have snapped right
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Right;
                                offset.X        = lastRectangle.Right - mouseLoc.X;
                            }

                            horizontalComponentIdentified = true;
                        }
                        else if (!verticalComponentIdentified && line.y1 == line.y2)
                        {
                            //check for vertical equality
                            if (line.y1 == lastRectangle.Top)
                            {
                                //we had a line on the top of the box - so we must have snapped top
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Top;
                                offset.Y        = lastRectangle.Top - mouseLoc.Y;
                            }
                            else if (line.y1 == lastRectangle.Bottom)
                            {
                                //we had a line on the bottom of the box - so we must have snapped bottom
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Bottom;
                                offset.Y        = lastRectangle.Bottom - mouseLoc.Y;
                            }

                            verticalComponentIdentified = true;
                        }
                    }
                    else if ((line.LineType == DragAssistanceManager.LineType.Margin) ||
                             (line.LineType == DragAssistanceManager.LineType.Padding))
                    {
                        if (!verticalComponentIdentified && line.x1 == line.x2)
                        {
                            //now, we're looking at a vertical margin line - is it above?
                            if (Math.Max(line.y1, line.y2) <= lastRectangle.Top)
                            {
                                //aha - we had a margin line at the top of the box
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Top;
                                offset.Y        = lastRectangle.Top - mouseLoc.Y;
                            }
                            else
                            {
                                //aha - we had a margin line at the bottom of the box
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Bottom;
                                offset.Y        = lastRectangle.Bottom - mouseLoc.Y;
                            }

                            verticalComponentIdentified = true;
                        }
                        else if (!horizontalComponentIdentified && line.y1 == line.y2)
                        {
                            //now, we're looking at a horz margin line - is it left?
                            if (Math.Max(line.x1, line.x2) <= lastRectangle.Left)
                            {
                                //aha - we had a margin line at the left of the box
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Left;
                                offset.X        = lastRectangle.Left - mouseLoc.X;
                            }
                            else
                            {
                                //aha - we had a margin line at the right of the box
                                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Right;
                                offset.X        = lastRectangle.Right - mouseLoc.X;
                            }

                            horizontalComponentIdentified = true;
                        }
                    }

                    if (horizontalComponentIdentified && verticalComponentIdentified)
                    {
                        //we've found both components - stop looping
                        break;
                    }
                }
            }

            //set default values is we haven't identified any 'snaps'
            if (!horizontalComponentIdentified)
            {
                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Left;
                offset.X        = lastRectangle.Left - mouseLoc.X;
            }

            if (!verticalComponentIdentified)
            {
                snapDirections |= ToolboxSnapDragDropEventArgs.SnapDirection.Top;
                offset.Y        = lastRectangle.Top - mouseLoc.Y;
            }

            //create our arg and pass it back
            return(new ToolboxSnapDragDropEventArgs(snapDirections, offset, e));
        }