Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BringToFront() and Focus() should un-minimize the Window #2647

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Eto.Gtk/Forms/GtkWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ public WindowState WindowState
Control.Unfullscreen();
if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified))
Control.Deiconify();
if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified))
Control.Present();
}
Control.Maximize();
break;
Expand All @@ -738,6 +740,8 @@ public WindowState WindowState
Control.Unmaximize();
if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified))
Control.Deiconify();
if (gdkWindow.State.HasFlag(Gdk.WindowState.Iconified))
Control.Present();
}
break;
}
Expand Down Expand Up @@ -783,7 +787,18 @@ public Screen Screen

protected override void GrabFocus() => Control.Present();

public void BringToFront() => Control.GetWindow()?.Raise();
public void BringToFront()
{
if (WindowState == WindowState.Minimized)
{
Control.Deiconify();
// if it didn't work, present it
if (WindowState == WindowState.Minimized)
Control.Present();
}

Control.GetWindow()?.Raise();
}

public void SendToBack() => Control.GetWindow()?.Lower();

Expand Down
22 changes: 20 additions & 2 deletions src/Eto.WinForms/Forms/WindowHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,7 @@ public WindowStyle WindowStyle

public virtual void BringToFront()
{
if (Control.WindowState == swf.FormWindowState.Minimized)
Control.WindowState = swf.FormWindowState.Normal;
RestoreFromMinimized();

var hWnd = NativeHandle;
if (hWnd != IntPtr.Zero)
Expand All @@ -557,6 +556,25 @@ public virtual void BringToFront()

public void SendToBack() => Control.SendToBack();

public override void Focus()
{
RestoreFromMinimized();

base.Focus();
}

private void RestoreFromMinimized()
{
if (Control.WindowState == swf.FormWindowState.Minimized)
{
var placement = new Win32.WINDOWPLACEMENT();
if (Win32.GetWindowPlacement(NativeHandle, ref placement) && placement.flags.HasFlag(Win32.WPF.RESTORETOMAXIMIZED))
Control.WindowState = swf.FormWindowState.Maximized;
else
Control.WindowState = swf.FormWindowState.Normal;
}
}

public virtual void SetOwner(Window owner)
{
Control.Owner = owner.ToSWF();
Expand Down
24 changes: 24 additions & 0 deletions src/Eto.WinForms/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,5 +768,29 @@ public struct SHSTOCKICONINFO
/// <returns>N/A</returns>
[DllImport("User32.dll")]
public static extern int DestroyIcon(IntPtr hIcon);

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

[Flags]
public enum WPF : int
{
SETMINPOSITION = 0x01,
RESTORETOMAXIMIZED = 0x02,
ASYNCWINDOWPLACEMENT = 0x04
}

[StructLayout(LayoutKind.Sequential)]
public struct WINDOWPLACEMENT
{
public int length;
public WPF flags;
public int showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
}

}
}
7 changes: 7 additions & 0 deletions src/Eto.Wpf/Forms/WpfWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,13 @@ void SetWindowChrome(bool enabled)
RestoreWindowStyle(oldStyle);
}

public override void Focus()
{
if (Control.WindowState == sw.WindowState.Minimized)
Control.WindowState = sw.WindowState.Normal;
base.Focus();
}

public void BringToFront()
{
if (Control.WindowState == sw.WindowState.Minimized)
Expand Down
Loading