Exemplo n.º 1
0
        public void DecorationMouseUp(HitTestValues hit, Point p)
        {
            NativeMethods.ReleaseCapture();
            var pt = new POINTS {
                X = (short)p.X, Y = (short)p.Y
            };

            NativeMethods.SendMessage(Handle, (int)WindowMessages.WM_NCLBUTTONUP, (int)hit, pt);
        }
Exemplo n.º 2
0
        private static void ResizeWindow(Window window, ResizeDirection direction)
        {
            ReleaseCapture();
            HitTestValues dir = GetHitTestValue(direction);

            if (dir != HitTestValues.HTTRANSPARENT)
            {
                SendMessage(new WindowInteropHelper(window).Handle, WM_NCLBUTTONDOWN, (int)dir, 0);
            }
        }
        public static Vector2 GetEdgeDistance(out HitTestValues cursorPositionFlag)
        {
            var globalCursorPosition = GetCursorPosition();
            var windowRectPoints     = WindowManager.GetWindowRectPoints();

            cursorPositionFlag = GetCursorPositionFlag();

            var distance = new Vector2();

            if (cursorPositionFlag == HitTestValues.LeftBorder)
            {
                distance.x = Mathf.Abs(globalCursorPosition.x - windowRectPoints.Left);
            }

            else if (cursorPositionFlag == HitTestValues.RightBorder)
            {
                distance.x = Mathf.Abs(globalCursorPosition.x - windowRectPoints.Right);
            }

            else if (cursorPositionFlag == HitTestValues.TopBorder)
            {
                distance.y = Mathf.Abs(globalCursorPosition.y - windowRectPoints.Top);
            }

            else if (cursorPositionFlag == HitTestValues.BottomBorder)
            {
                distance.y = Mathf.Abs(globalCursorPosition.y - windowRectPoints.Bottom);
            }

            else if (cursorPositionFlag == HitTestValues.TopLeftBorder)
            {
                distance.x = Mathf.Abs(globalCursorPosition.x - windowRectPoints.Left);
                distance.y = Mathf.Abs(globalCursorPosition.y - windowRectPoints.Top);
            }

            else if (cursorPositionFlag == HitTestValues.TopRightBorder)
            {
                distance.x = Mathf.Abs(globalCursorPosition.x - windowRectPoints.Right);
                distance.y = Mathf.Abs(globalCursorPosition.y - windowRectPoints.Top);
            }

            else if (cursorPositionFlag == HitTestValues.BottomLeftBorder)
            {
                distance.x = Mathf.Abs(globalCursorPosition.x - windowRectPoints.Left);
                distance.y = Mathf.Abs(globalCursorPosition.y - windowRectPoints.Bottom);
            }
            else if (cursorPositionFlag == HitTestValues.BottomRightBorder)
            {
                distance.x = Mathf.Abs(globalCursorPosition.x - windowRectPoints.Right);
                distance.y = Mathf.Abs(globalCursorPosition.y - windowRectPoints.Bottom);
            }

            return(distance);
        }
        public void OnPointerUp(PointerEventData eventData)
        {
            if (WindowManager.Resizable)
            {
                _beginningCursorEdgeDistance = CursorManager.GetEdgeDistance(out _mouseDownCursorFlag);
                _mouseDownCursorFlag         = HitTestValues.Client;
                _isMouseDown = false;

                if (!WindowManager.Bordered && !WindowManager.Maximized)
                {
                    blackPanel.SetActive(false);
                    WindowManager.LockWindowUpdate(false);
                }
            }
        }
Exemplo n.º 5
0
        private IntPtr WindowFromPoint(Point point, uint timeout, ref HitTestValues hitTest, IntPtr lastestWindowFromPoint)
        {
            var window = WindowFromPoint(point);

            if (window != IntPtr.Zero)
            {
                IntPtr result;
                if (
                    SendMessageTimeout(window, (uint)WM.NCHITTEST, IntPtr.Zero, MAKELPARAM(point.X, point.Y),
                                       SendMessageTimeoutFlags.SMTO_ABORTIFHUNG | SendMessageTimeoutFlags.SMTO_NORMAL, timeout,
                                       out result) == IntPtr.Zero)
                {
                    window = IntPtr.Zero;
                }
                else
                {
                    var hitTestResult = (HitTestValues)result;
                    if (hitTestResult == HitTestValues.HTTRANSPARENT)
                    {
                        if (window == lastestWindowFromPoint)
                        {
                            //prevent infinite loop
                            return(lastestWindowFromPoint);
                        }
                        var currentWindow = window;
                        SetWindowLong(window, GWL_STYLE,
                                      (int)
                                      ((WindowStyles)GetWindowLong(currentWindow, GWL_STYLE) |
                                       WindowStyles.WS_DISABLED));
                        window = WindowFromPoint(point, timeout, ref hitTest, window);
                        SetWindowLong(window, GWL_STYLE,
                                      (int)
                                      ((WindowStyles)GetWindowLong(currentWindow, GWL_STYLE) &
                                       ~WindowStyles.WS_DISABLED));
                    }
                    else
                    {
                        if (hitTest == 0)
                        {
                            hitTest = hitTestResult;
                        }
                    }
                }
            }
            return(window);
        }
Exemplo n.º 6
0
 public void DecorationMouseUp(HitTestValues hit)
 {
     DecorationMouseUp(hit, MousePosition);
 }
Exemplo n.º 7
0
 public void DecorationMouseUp(HitTestValues hit, Point p)
 {
     NativeMethods.ReleaseCapture();
     var pt = new POINTS { X = (short)p.X, Y = (short)p.Y };
     NativeMethods.SendMessage(Handle, (int)WindowMessages.WM_NCLBUTTONUP, (int)hit, pt);
 }
Exemplo n.º 8
0
 void DecorationMouseDown(MouseEventArgs e, HitTestValues h)
 {
   if (e.Button == MouseButtons.Left) DecorationMouseDown(h);
 }
Exemplo n.º 9
0
 public void DecorationMouseUp(HitTestValues hit)
 {
     DecorationMouseUp(hit, MousePosition);
 }
Exemplo n.º 10
0
 void FormBorderMouseUp(HitTestValues hit)
 {
     FormBorderMouseUp(hit, MousePosition);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="value">Value, that will be transmitted to <see cref="Form"/>, when triggered.</param>
 public SideGrip(HitTestValues value)
 {
     // ...
     _hitTestValue = value;
     Location      = Point.Empty;
 }
Exemplo n.º 12
0
        private void MouseEvent(IntPtr window, WINDOWINFO windowinfo, HitTestValues hitTest, WM message, WM ncMessage, IntPtr clientCursorPos, IntPtr screenCursorPos)
        {
            if (message == WM.LBUTTONDOWN || message == WM.MBUTTONDOWN || message == WM.RBUTTONDOWN)
            {
                var topParent = GetAncestor(window, GetAncestorFlags.GetRoot);

                if (topParent != _lastWindow)
                {
                    IntPtr        result;
                    MouseActivate mouseActivateResult;
                    if (
                        SendMessageTimeout(window, (uint)WM.MOUSEACTIVATE, topParent,
                                           MAKELPARAM((int)hitTest, (int)message),
                                           SendMessageTimeoutFlags.SMTO_ABORTIFHUNG | SendMessageTimeoutFlags.SMTO_NORMAL, 100,
                                           out result) != IntPtr.Zero &&
                        (((mouseActivateResult = (MouseActivate)result) == MouseActivate.MA_ACTIVATEANDEAT) ||
                         mouseActivateResult == MouseActivate.MA_NOACTIVATEANDEAT))
                    {
                        return;
                    }

                    NativeMethods.SetWindowPos(topParent, new IntPtr(HWND_TOPMOST), 0, 0, 0, 0,
                                               SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize | SetWindowPosFlags.ShowWindow);
                    _lastWindow = topParent;
                }
            }

            NativeMethods.PostMessage(new HandleRef(null, window), WM.SETCURSOR, window,
                                      MAKELPARAM((int)hitTest, (int)message));

            if (hitTest == HitTestValues.HTCLIENT)
            {
                NativeMethods.PostMessage(new HandleRef(null, window), message, (IntPtr)MK_LBUTTON, clientCursorPos);
                return;
            }

            SysCommands command = 0;

            switch (hitTest)
            {
            case HitTestValues.HTSYSMENU:
                if (ncMessage == WM.NCLBUTTONDBLCLK)
                {
                    command = SysCommands.SC_CLOSE;
                }
                else if (ncMessage == WM.NCRBUTTONUP || ncMessage == WM.NCLBUTTONDOWN)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMINBUTTON:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    if (((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MINIMIZEBOX) != 0)
                    {
                        command = SysCommands.SC_MINIMIZE;
                    }
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMAXBUTTON:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    if (((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MAXIMIZEBOX) != 0)
                    {
                        command = ((WindowStyles)windowinfo.dwStyle & WindowStyles.WS_MAXIMIZE) == 0
                                ? SysCommands.SC_MAXIMIZE
                                : SysCommands.SC_RESTORE;
                    }
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTCLOSE:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    command = SysCommands.SC_CLOSE;
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTHELP:
                if (ncMessage == WM.NCLBUTTONUP)
                {
                    command = SysCommands.SC_CONTEXTHELP;
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            case HitTestValues.HTMENU:
                if (ncMessage == WM.NCLBUTTONDOWN)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), (WM)VncMessage, (IntPtr)VMW_EXECUTE_MENU, IntPtr.Zero);
                }
                else if (ncMessage == WM.NCMOUSEMOVE)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), (WM)VncMessage, (IntPtr)VMW_HILITE_MENU, IntPtr.Zero);
                }
                break;

            case HitTestValues.HTCAPTION:
                if (ncMessage == WM.NCLBUTTONDBLCLK)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), ncMessage, (IntPtr)hitTest, clientCursorPos);
                }
                else if (ncMessage == WM.NCRBUTTONUP)
                {
                    command = (SysCommands)0xFFFF;
                }
                break;

            default:
                NativeMethods.PostMessage(new HandleRef(null, window),
                                          message,
                                          (IntPtr)MK_LBUTTON, clientCursorPos);
                NativeMethods.PostMessage(new HandleRef(null, window), ncMessage, (IntPtr)hitTest, screenCursorPos);
                break;
            }

            if (command != 0)
            {
                if (command == (SysCommands)0xFFFF)
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), WM.CONTEXTMENU, (IntPtr)command, clientCursorPos);
                }
                else
                {
                    NativeMethods.PostMessage(new HandleRef(null, window), WM.SYSCOMMAND, (IntPtr)command, clientCursorPos);
                }
            }
        }
        public static void WindowSizeChange(Vector2 beginningCursorEdgeDistance, HitTestValues beginningCursorFlag)
        {
            if (beginningCursorFlag == HitTestValues.Client)
            {
                return;
            }

            var globalCursorPosition = CursorManager.GetCursorPosition();
            var windowRectPoints     = GetWindowRectPoints();

            var newWindowRect = GetWindowRect();


            if (KeepAspectRatio)
            {
                float aspectSizeValue;
                switch (beginningCursorFlag)
                {
                case HitTestValues.LeftBorder:
                case HitTestValues.TopLeftBorder:
                case HitTestValues.BottomLeftBorder:
                    newWindowRect = WindowRectResizeLeft
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );

                    aspectSizeValue      = newWindowRect.width / AspectRatio.x;
                    newWindowRect.height = aspectSizeValue * AspectRatio.y;
                    break;

                case HitTestValues.RightBorder:
                case HitTestValues.BottomRightBorder:
                case HitTestValues.TopRightBorder:
                    newWindowRect = WindowRectResizeRight
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );

                    aspectSizeValue      = newWindowRect.width / AspectRatio.x;
                    newWindowRect.height = aspectSizeValue * AspectRatio.y;
                    break;

                case HitTestValues.TopBorder:
                    newWindowRect = WindowRectResizeTop
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );

                    aspectSizeValue     = newWindowRect.height / AspectRatio.y;
                    newWindowRect.width = aspectSizeValue * AspectRatio.x;
                    break;

                case HitTestValues.BottomBorder:
                    newWindowRect = WindowRectResizeBottom
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );

                    aspectSizeValue     = newWindowRect.height / AspectRatio.y;
                    newWindowRect.width = aspectSizeValue * AspectRatio.x;
                    break;
                }
            }
            else
            {
                switch (beginningCursorFlag)
                {
                case HitTestValues.LeftBorder:
                {
                    newWindowRect = WindowRectResizeLeft
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;
                }

                case HitTestValues.RightBorder:
                {
                    newWindowRect = WindowRectResizeRight
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;
                }

                case HitTestValues.TopBorder:
                {
                    newWindowRect = WindowRectResizeTop
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;
                }

                case HitTestValues.BottomBorder:
                {
                    newWindowRect = WindowRectResizeBottom
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;
                }

                case HitTestValues.TopLeftBorder:
                    newWindowRect = WindowRectResizeLeft
                                        (beginningCursorEdgeDistance,
                                        windowRectPoints,
                                        globalCursorPosition,
                                        newWindowRect
                                        );
                    newWindowRect = WindowRectResizeTop
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;

                case HitTestValues.TopRightBorder:
                    newWindowRect = WindowRectResizeRight
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    newWindowRect = WindowRectResizeTop
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;

                case HitTestValues.BottomLeftBorder:
                    newWindowRect = WindowRectResizeLeft
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );

                    newWindowRect = WindowRectResizeBottom
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;

                case HitTestValues.BottomRightBorder:
                    newWindowRect = WindowRectResizeRight
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    newWindowRect = WindowRectResizeBottom
                                    (
                        beginningCursorEdgeDistance,
                        windowRectPoints,
                        globalCursorPosition,
                        newWindowRect
                                    );
                    break;
                }
            }


            MoveWindow(newWindowRect, true);
        }
Exemplo n.º 14
0
 private void SetStyle(Direction direction)
 {
     var(hitTestValues, cursor) = BuildStyle(direction);
     _hitTestValue = hitTestValues;
     _cursor       = cursor;
 }