Ejemplo n.º 1
0
 public void UnstickMe(IFormAdapter window)
 {
     if (stuckWindows.ContainsKey(window))
     {
         stuckWindows.Remove(window);
     }
 }
        /// <summary>
        /// Make the form Sticky
        /// </summary>
        /// <param name="form">Form to be made sticky</param>
        public StickyWindow(IFormAdapter form)
        {
            resizingForm = false;
            movingForm   = false;

            originalForm = form;

            formRect       = Rectangle.Empty;
            formOffsetRect = Rectangle.Empty;

            formOffsetPoint = Point.Empty;
            offsetPoint     = Point.Empty;
            mousePoint      = Point.Empty;

            stickOnMove   = true;
            stickOnResize = true;
            stickToScreen = true;
            stickToOther  = true;

            DefaultMessageProcessor = new ProcessMessage(DefaultMsgProcessor);
            MoveMessageProcessor    = new ProcessMessage(MoveMsgProcessor);
            ResizeMessageProcessor  = new ProcessMessage(ResizeMsgProcessor);
            MessageProcessor        = DefaultMessageProcessor;

            AssignHandle(originalForm.Handle);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Make the form Sticky
        /// </summary>
        /// <param name="form">Form to be made sticky</param>
        public StickyWindow(IFormAdapter form)
        {
            _resizingForm = false;
            _movingForm   = false;

            _originalForm = form;

            _formRect       = Rectangle.Empty;
            _formOffsetRect = Rectangle.Empty;

            _formOffsetPoint = Point.Empty;
            _offsetPoint     = Point.Empty;
            _mousePoint      = Point.Empty;

            StickOnMove   = true;
            StickOnResize = true;
            StickToScreen = true;
            StickToOther  = true;

            _defaultMessageProcessor = DefaultMsgProcessor;
            _moveMessageProcessor    = MoveMsgProcessor;
            _resizeMessageProcessor  = ResizeMsgProcessor;
            _messageProcessor        = _defaultMessageProcessor;

            AssignHandle(_originalForm.Handle);
        }
 /// <summary>
 /// Unregister a form from the external references.
 /// <see cref="RegisterExternalReferenceForm"/>
 /// </summary>
 /// <param name="frmExternal">External window that will was used as reference</param>
 public static void UnregisterExternalReferenceForm(IFormAdapter frmExternal)
 {
     GlobalStickyWindows.Remove(frmExternal);
 }
 /// <summary>
 /// Register a new form as an external reference form.
 /// All Sticky windows will try to stick to the external references
 /// Use this to register your MainFrame so the child windows try to stick to it, when your MainFrame is NOT a sticky window
 /// </summary>
 /// <param name="frmExternal">External window that will be used as reference</param>
 public static void RegisterExternalReferenceForm(IFormAdapter frmExternal)
 {
     GlobalStickyWindows.Add(frmExternal);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bInsideStick">Allow snapping on the inside (eg: window to screen)</param>
        public StickDir IsStuckTo(IFormAdapter window, bool bInsideStick)
        {
            int fullStickGap = 2;
            if (window == this.originalForm)
                return StickDir.None;

            Rectangle fromRect = originalForm.Bounds;
            Rectangle toRect = window.Bounds;
            StickDir result = StickDir.None;

            if (fromRect.Bottom >= (toRect.Top - stickGap) && fromRect.Top <= (toRect.Bottom + stickGap))
            {
                if (bInsideStick)
                {
                    if (fromRect.Left <= toRect.Left + fullStickGap && fromRect.Left >= toRect.Left - fullStickGap)
                    {
                        // stuck on left
                        result = result | StickDir.HorizontalInside | StickDir.Left;
                    }
                    if (fromRect.Right <= toRect.Right + fullStickGap && fromRect.Right >= toRect.Right - fullStickGap)
                    {
                        // stuck on right
                        result = result | StickDir.HorizontalInside | StickDir.Right;
                    }
                }
                if (fromRect.Left + fromRect.Width <= toRect.Left + fullStickGap && fromRect.Left + fromRect.Width >= toRect.Left - fullStickGap)
                {
                    // right 2 left
                    result = result | StickDir.Left;
                }
                if (toRect.Left + toRect.Width <= fromRect.Left + fullStickGap && toRect.Left + toRect.Width >= fromRect.Left - fullStickGap)
                {
                    // left 2 right
                    result = result | StickDir.Right;
                }
            }

            if (fromRect.Right >= (toRect.Left - stickGap) && fromRect.Left <= (toRect.Right + stickGap))
            {
                if (bInsideStick)
                {
                    if (fromRect.Top <= toRect.Top + fullStickGap && fromRect.Top >= toRect.Top - fullStickGap)
                    {
                        // stuck on top
                        result = result | StickDir.VerticalInside | StickDir.Top;
                    }
                    if (fromRect.Bottom <= toRect.Bottom + fullStickGap && fromRect.Bottom >= toRect.Bottom - fullStickGap)
                    {
                        // stuck on bottom
                        result = result | StickDir.VerticalInside | StickDir.Bottom;
                    }
                }
                if (fromRect.Top + fromRect.Height <= toRect.Top + fullStickGap && fromRect.Top + fromRect.Height >= toRect.Top - fullStickGap)
                {
                    // top 2 bottom
                    if ((result & StickDir.Top) != StickDir.Top)
                        result = result | StickDir.Top;
                }
                if (toRect.Top + toRect.Height <= fromRect.Top + fullStickGap && toRect.Top + toRect.Height >= fromRect.Top - fullStickGap)
                {
                    // bottom 2 windows
                    if ((result & StickDir.Bottom) != StickDir.Bottom)
                        result = result | StickDir.Bottom;
                }
            }
            return result;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Make the form Sticky
        /// </summary>
        /// <param name="form">Form to be made sticky</param>
        public StickyWindow(IFormAdapter form)
        {
            resizingForm = false;
            movingForm = false;

            originalForm = form;
            form.StickyWindow = this;

            formRect = Rectangle.Empty;
            formOffsetRect = Rectangle.Empty;

            formOffsetPoint = Point.Empty;
            offsetPoint = Point.Empty;
            mousePoint = Point.Empty;

            stickOnMove = true;
            stickOnResize = true;
            stickToScreen = true;
            stickToOther = true;

            moveStuck = true;

            DefaultMessageProcessor = new ProcessMessage(DefaultMsgProcessor);
            MoveMessageProcessor = new ProcessMessage(MoveMsgProcessor);
            ResizeMessageProcessor = new ProcessMessage(ResizeMsgProcessor);
            MessageProcessor = DefaultMessageProcessor;

            AssignHandle(originalForm.Handle);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Unregister a form from the external references.
 /// <see cref="RegisterExternalReferenceForm"/>
 /// </summary>
 /// <param name="frmExternal">External window that will was used as reference</param>
 public static void UnregisterExternalReferenceForm(IFormAdapter frmExternal)
 {
     GlobalStickyWindows.Remove(frmExternal);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Register a new form as an external reference form.
 /// All Sticky windows will try to stick to the external references
 /// Use this to register your MainFrame so the child windows try to stick to it, when your MainFrame is NOT a sticky window
 /// </summary>
 /// <param name="frmExternal">External window that will be used as reference</param>
 public static void RegisterExternalReferenceForm(IFormAdapter frmExternal)
 {
     GlobalStickyWindows.Add(frmExternal);
 }
Ejemplo n.º 10
0
        public static Rectangle PositionRelativeTo(IFormAdapter window, StickDir direction, Rectangle size)
        {
            Rectangle newPosition = size;
            if (direction == StickDir.None)
            {
                //nothing more
                newPosition = size;
            }
            // Stuck to side from top to bottom
            if (direction == (StickDir.Left | StickDir.Top | StickDir.Bottom | StickDir.VerticalInside) ||
                direction == (StickDir.Right | StickDir.Top | StickDir.Bottom | StickDir.VerticalInside))
            {
                newPosition.Height = window.Bounds.Height;
            }

            // Stuck to side from left to right
            if (direction == (StickDir.Top | StickDir.Left | StickDir.Right | StickDir.HorizontalInside) ||
                direction == (StickDir.Bottom | StickDir.Left | StickDir.Right | StickDir.HorizontalInside))
            {
                newPosition.Width = window.Bounds.Width;
            }

            // Stuck to left from inside
            if ((direction & (StickDir.Left | StickDir.HorizontalInside)) == (StickDir.Left | StickDir.HorizontalInside))
            {
                newPosition.X = window.Bounds.X;
            }
            // Stuck to right from inside
            else if ((direction & (StickDir.Right | StickDir.HorizontalInside)) == (StickDir.Right | StickDir.HorizontalInside))
            {
                newPosition.X = window.Bounds.X + (window.Bounds.Width - size.Width);
            }
            // Stuck to left from outside
            else if ((direction & StickDir.Left) == StickDir.Left)
            {
                newPosition.X = window.Bounds.X - size.Width;
            }
            // Stuck to right from outside
            else if ((direction & StickDir.Right) == StickDir.Right)
            {
                newPosition.X = window.Bounds.X + window.Bounds.Width;
            }

             
            // Stuck to top from inside
            if ((direction & (StickDir.Top | StickDir.VerticalInside)) == (StickDir.Top | StickDir.VerticalInside))
            {
                newPosition.Y = window.Bounds.Y;
            }
            // Stuck to bottom from inside
            else if ((direction & (StickDir.Bottom | StickDir.VerticalInside)) == (StickDir.Bottom | StickDir.VerticalInside))
            {
                newPosition.Y = window.Bounds.Y + (window.Bounds.Height - size.Height);
            }
            // Stuck to top from outside
            else if ((direction & StickDir.Top) == StickDir.Top)
            {
                newPosition.Y = window.Bounds.Y - size.Height;
            }
            // Stuck to bottom from outside
            else if ((direction & StickDir.Bottom) == StickDir.Bottom)               
            {
                newPosition.Y = window.Bounds.Y + window.Bounds.Height;
            }
            return newPosition;
        }
Ejemplo n.º 11
0
 public void UnstickMe(IFormAdapter window)
 {
     if (stuckWindows.ContainsKey(window))
         stuckWindows.Remove(window);
 }
Ejemplo n.º 12
0
        public static Rectangle PositionRelativeTo(IFormAdapter window, StickDir direction, Rectangle size)
        {
            Rectangle newPosition = size;

            if (direction == StickDir.None)
            {
                //nothing more
                newPosition = size;
            }
            // Stuck to side from top to bottom
            if (direction == (StickDir.Left | StickDir.Top | StickDir.Bottom | StickDir.VerticalInside) ||
                direction == (StickDir.Right | StickDir.Top | StickDir.Bottom | StickDir.VerticalInside))
            {
                newPosition.Height = window.Bounds.Height;
            }

            // Stuck to side from left to right
            if (direction == (StickDir.Top | StickDir.Left | StickDir.Right | StickDir.HorizontalInside) ||
                direction == (StickDir.Bottom | StickDir.Left | StickDir.Right | StickDir.HorizontalInside))
            {
                newPosition.Width = window.Bounds.Width;
            }

            // Stuck to left from inside
            if ((direction & (StickDir.Left | StickDir.HorizontalInside)) == (StickDir.Left | StickDir.HorizontalInside))
            {
                newPosition.X = window.Bounds.X;
            }
            // Stuck to right from inside
            else if ((direction & (StickDir.Right | StickDir.HorizontalInside)) == (StickDir.Right | StickDir.HorizontalInside))
            {
                newPosition.X = window.Bounds.X + (window.Bounds.Width - size.Width);
            }
            // Stuck to left from outside
            else if ((direction & StickDir.Left) == StickDir.Left)
            {
                newPosition.X = window.Bounds.X - size.Width;
            }
            // Stuck to right from outside
            else if ((direction & StickDir.Right) == StickDir.Right)
            {
                newPosition.X = window.Bounds.X + window.Bounds.Width;
            }


            // Stuck to top from inside
            if ((direction & (StickDir.Top | StickDir.VerticalInside)) == (StickDir.Top | StickDir.VerticalInside))
            {
                newPosition.Y = window.Bounds.Y;
            }
            // Stuck to bottom from inside
            else if ((direction & (StickDir.Bottom | StickDir.VerticalInside)) == (StickDir.Bottom | StickDir.VerticalInside))
            {
                newPosition.Y = window.Bounds.Y + (window.Bounds.Height - size.Height);
            }
            // Stuck to top from outside
            else if ((direction & StickDir.Top) == StickDir.Top)
            {
                newPosition.Y = window.Bounds.Y - size.Height;
            }
            // Stuck to bottom from outside
            else if ((direction & StickDir.Bottom) == StickDir.Bottom)
            {
                newPosition.Y = window.Bounds.Y + window.Bounds.Height;
            }
            return(newPosition);
        }
Ejemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bInsideStick">Allow snapping on the inside (eg: window to screen)</param>
        public StickDir IsStuckTo(IFormAdapter window, bool bInsideStick)
        {
            int fullStickGap = 2;

            if (window == this.originalForm)
            {
                return(StickDir.None);
            }

            Rectangle fromRect = originalForm.Bounds;
            Rectangle toRect   = window.Bounds;
            StickDir  result   = StickDir.None;

            if (fromRect.Bottom >= (toRect.Top - stickGap) && fromRect.Top <= (toRect.Bottom + stickGap))
            {
                if (bInsideStick)
                {
                    if (fromRect.Left <= toRect.Left + fullStickGap && fromRect.Left >= toRect.Left - fullStickGap)
                    {
                        // stuck on left
                        result = result | StickDir.HorizontalInside | StickDir.Left;
                    }
                    if (fromRect.Right <= toRect.Right + fullStickGap && fromRect.Right >= toRect.Right - fullStickGap)
                    {
                        // stuck on right
                        result = result | StickDir.HorizontalInside | StickDir.Right;
                    }
                }
                if (fromRect.Left + fromRect.Width <= toRect.Left + fullStickGap && fromRect.Left + fromRect.Width >= toRect.Left - fullStickGap)
                {
                    // right 2 left
                    result = result | StickDir.Left;
                }
                if (toRect.Left + toRect.Width <= fromRect.Left + fullStickGap && toRect.Left + toRect.Width >= fromRect.Left - fullStickGap)
                {
                    // left 2 right
                    result = result | StickDir.Right;
                }
            }

            if (fromRect.Right >= (toRect.Left - stickGap) && fromRect.Left <= (toRect.Right + stickGap))
            {
                if (bInsideStick)
                {
                    if (fromRect.Top <= toRect.Top + fullStickGap && fromRect.Top >= toRect.Top - fullStickGap)
                    {
                        // stuck on top
                        result = result | StickDir.VerticalInside | StickDir.Top;
                    }
                    if (fromRect.Bottom <= toRect.Bottom + fullStickGap && fromRect.Bottom >= toRect.Bottom - fullStickGap)
                    {
                        // stuck on bottom
                        result = result | StickDir.VerticalInside | StickDir.Bottom;
                    }
                }
                if (fromRect.Top + fromRect.Height <= toRect.Top + fullStickGap && fromRect.Top + fromRect.Height >= toRect.Top - fullStickGap)
                {
                    // top 2 bottom
                    if ((result & StickDir.Top) != StickDir.Top)
                    {
                        result = result | StickDir.Top;
                    }
                }
                if (toRect.Top + toRect.Height <= fromRect.Top + fullStickGap && toRect.Top + toRect.Height >= fromRect.Top - fullStickGap)
                {
                    // bottom 2 windows
                    if ((result & StickDir.Bottom) != StickDir.Bottom)
                    {
                        result = result | StickDir.Bottom;
                    }
                }
            }
            return(result);
        }