Ejemplo n.º 1
0
 internal static void DoWindowTitleThumbOnPreviewMouseLeftButtonUp(SimpleMetroWindow window, MouseButtonEventArgs mouseButtonEventArgs)
 {
     if (mouseButtonEventArgs.Source == mouseButtonEventArgs.OriginalSource)
     {
         Mouse.Capture(null);
     }
 }
Ejemplo n.º 2
0
 internal static void DoWindowTitleThumbSystemMenuOnMouseRightButtonUp(SimpleMetroWindow window, MouseButtonEventArgs e)
 {
     if (window.ShowSystemMenuOnRightClick)
     {
         // show menu only if mouse pos is on title bar or if we have a window with none style and no title bar
         var mousePos = e.GetPosition(window);
         ////if ((mousePos.Y <= window.TitlebarHeight && window.TitlebarHeight > 0) || (window.UseNoneWindowStyle && window.TitlebarHeight <= 0))
         ////{
         ShowSystemMenuPhysicalCoordinates(window, window.PointToScreen(mousePos));
         ////}
     }
 }
Ejemplo n.º 3
0
 internal static void DoWindowTitleThumbChangeWindowStateOnMouseDoubleClick(SimpleMetroWindow window, MouseButtonEventArgs mouseButtonEventArgs)
 {
     // restore/maximize only with left button
     if (mouseButtonEventArgs.ChangedButton == MouseButton.Left)
     {
         // we can maximize or restore the window if the title bar height is set (also if title bar is hidden)
         var canResize         = window.ResizeMode == ResizeMode.CanResizeWithGrip || window.ResizeMode == ResizeMode.CanResize;
         var mousePos          = Mouse.GetPosition(window);
         var isMouseOnTitlebar = true; //// var isMouseOnTitlebar = mousePos.Y <= window.TitlebarHeight && window.TitlebarHeight > 0;
         if (canResize && isMouseOnTitlebar)
         {
             if (window.WindowState == WindowState.Maximized)
             {
                 SystemCommands.RestoreWindow(window);
             }
             else
             {
                 SystemCommands.MaximizeWindow(window);
             }
             mouseButtonEventArgs.Handled = true;
         }
     }
 }
Ejemplo n.º 4
0
        internal static void DoWindowTitleThumbMoveOnDragDelta(IMetroThumb thumb, SimpleMetroWindow window, DragDeltaEventArgs dragDeltaEventArgs)
        {
            if (thumb == null)
            {
                throw new ArgumentNullException(nameof(thumb));
            }
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            // drag only if IsWindowDraggable is set to true
            if (!window.IsWindowDraggable ||
                (!(Math.Abs(dragDeltaEventArgs.HorizontalChange) > 2) && !(Math.Abs(dragDeltaEventArgs.VerticalChange) > 2)))
            {
                return;
            }

            // tage from DragMove internal code
            window.VerifyAccess();

            var cursorPos = NativeMethods.GetCursorPos();

            // if the window is maximized dragging is only allowed on title bar (also if not visible)
            var windowIsMaximized = window.WindowState == WindowState.Maximized;

            ////var isMouseOnTitlebar = Mouse.GetPosition(thumb).Y <= window.TitlebarHeight && window.TitlebarHeight > 0;
            ////if (!isMouseOnTitlebar && windowIsMaximized)
            ////{
            ////    return;
            ////}

            // for the touch usage
            UnsafeNativeMethods.ReleaseCapture();

            if (windowIsMaximized)
            {
                var          cursorXPos           = cursorPos.x;
                EventHandler windowOnStateChanged = null;
                windowOnStateChanged = (sender, args) =>
                {
                    //window.Top = 2;
                    //window.Left = Math.Max(cursorXPos - window.RestoreBounds.Width / 2, 0);

                    window.StateChanged -= windowOnStateChanged;
                    if (window.WindowState == WindowState.Normal)
                    {
                        Mouse.Capture(thumb, CaptureMode.Element);
                    }
                };
                window.StateChanged += windowOnStateChanged;
            }

            var criticalHandle = window.CriticalHandle;

            // DragMove works too
            // window.DragMove();
            // instead this 2 lines
            NativeMethods.SendMessage(criticalHandle, WM.SYSCOMMAND, (IntPtr)SC.MOUSEMOVE, IntPtr.Zero);
            NativeMethods.SendMessage(criticalHandle, WM.LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
        }