Пример #1
0
        private void TryStickBottom(StickContext top, Position currentPosition, ref int topPriority)
        {
            foreach (StickPoint other in pointProvider.ForBottom())
            {
                if (other.Handle == handle)
                {
                    continue;
                }

                if (topPriority < other.Priority)
                {
                    break;
                }

                if (top.TryStickTo(other.Value, currentPosition.Height))
                {
                    topPriority = other.Priority;
                }
            }
        }
Пример #2
0
        private void TryStickRight(StickContext left, Position currentPosition, ref int leftPriority)
        {
            foreach (StickPoint other in pointProvider.ForRight())
            {
                if (other.Handle == handle)
                {
                    continue;
                }

                if (leftPriority < other.Priority)
                {
                    break;
                }

                if (left.TryStickTo(other.Value, currentPosition.Width))
                {
                    leftPriority = other.Priority;
                }
            }
        }
Пример #3
0
        private void TryStickTop(StickContext top, ref int topPriority)
        {
            foreach (StickPoint other in pointProvider.ForTop())
            {
                if (other.Handle == handle)
                {
                    continue;
                }

                if (topPriority < other.Priority)
                {
                    break;
                }

                if (top.TryStickTo(other.Value))
                {
                    topPriority = other.Priority;
                }
            }
        }
Пример #4
0
        private void TryStickLeft(StickContext left, ref int leftPriority)
        {
            foreach (StickPoint other in pointProvider.ForLeft())
            {
                if (other.Handle == handle)
                {
                    continue;
                }

                if (leftPriority < other.Priority)
                {
                    break;
                }

                if (left.TryStickTo(other.Value))
                {
                    leftPriority = other.Priority;
                }
            }
        }
Пример #5
0
        private void WndProc2(IntPtr hWinEventHook, uint eventType, IntPtr handle, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            if (this.handle != handle)
            {
                return;
            }

            if (eventType == (uint)Win32.EventContants.EVENT_SYSTEM_MOVESIZESTART)
            {
                //Log("Starting to move or resize window '{0}' ('{1}', '{2}', '{3}', '{4}').", handle, idObject, idChild, dwEventThread, dwmsEventTime);
                initialPosition = GetWindowPositionOrDefault(handle);
            }
            else if (eventType == (uint)Win32.EventContants.EVENT_SYSTEM_MOVESIZEEND)
            {
                //Log("Resized or moved window '{0}' (from '{5}') ('{1}', '{2}', '{3}', '{4}').", handle, idObject, idChild, dwEventThread, dwmsEventTime, handle);

                Position currentPosition = GetWindowPositionOrDefault(handle);
                if (currentPosition == null)
                {
                    return;
                }

                Win32.RECT offset = GetWindowFrameOffset(handle, currentPosition);

                ResizeDirection resize = ResizeDirection.Empty;
                MoveDirection   move   = MoveDirection.Empty;

                if (initialPosition != null)
                {
                    if (initialPosition.Left < currentPosition.Left)
                    {
                        move |= MoveDirection.LeftToRight;
                    }
                    else if (initialPosition.Left > currentPosition.Left)
                    {
                        move |= MoveDirection.RightToLeft;
                    }

                    if (initialPosition.Top < currentPosition.Top)
                    {
                        move |= MoveDirection.TopToBottom;
                    }
                    else if (initialPosition.Top > currentPosition.Top)
                    {
                        move |= MoveDirection.BottomToTop;
                    }

                    if (initialPosition.Width != currentPosition.Width)
                    {
                        resize |= ResizeDirection.Width;
                    }

                    if (initialPosition.Height != currentPosition.Height)
                    {
                        resize |= ResizeDirection.Height;
                    }
                }

                //Log("User state: {0}x{1} at {2}x{3}.", currentPosition.Left, currentPosition.Top, currentPosition.Width, currentPosition.Height);

                StickContext left;
                if (resize.HasFlag(ResizeDirection.Width))
                {
                    left = new StickContext(currentPosition.Left, currentPosition.Width);
                }
                else
                {
                    left = new StickContext(currentPosition.Left);
                }

                StickContext top;
                if (resize.HasFlag(ResizeDirection.Height))
                {
                    top = new StickContext(currentPosition.Top, currentPosition.Height);
                }
                else
                {
                    top = new StickContext(currentPosition.Top);
                }

                int leftPriority = Int32.MaxValue;
                int topPriority  = Int32.MaxValue;

                if (move.HasFlag(MoveDirection.RightToLeft) || move.HasFlag(MoveDirection.LeftToRight))
                {
                    TryStickLeft(left, ref leftPriority);
                    TryStickRight(left, currentPosition, ref leftPriority);
                }

                if (move.HasFlag(MoveDirection.BottomToTop) || move.HasFlag(MoveDirection.TopToBottom))
                {
                    TryStickTop(top, ref topPriority);
                    TryStickBottom(top, currentPosition, ref topPriority);
                }

                if (move == MoveDirection.Empty && resize.HasFlag(ResizeDirection.Width))
                {
                    TryStickRight(left, currentPosition, ref leftPriority);
                }

                if (move == MoveDirection.Empty && resize.HasFlag(ResizeDirection.Height))
                {
                    TryStickBottom(top, currentPosition, ref topPriority);
                }

                Position targetPosition = new Position(
                    left.NewPosition - offset.Left,
                    top.NewPosition - offset.Top,
                    (left.IsResize ? left.NewSize : currentPosition.Width) - offset.Right + offset.Left,
                    (top.IsResize ? top.NewSize : currentPosition.Height) - offset.Bottom + offset.Top
                    );

                //Log("Stick state: {0}x{1} at {2}x{3}.", targetPosition.Left, targetPosition.Top, targetPosition.Width, targetPosition.Height);

                Win32.SetWindowPos(
                    handle,
                    IntPtr.Zero,
                    targetPosition.Left,
                    targetPosition.Top,
                    targetPosition.Width,
                    targetPosition.Height,
                    0
                    );
            }
        }