Skip to content

Commit

Permalink
Merge pull request #2136 from cwensley/curtis/windows-parent-focus-co…
Browse files Browse the repository at this point in the history
…ntinued

Wpf/WinForms: Focus parent for all dialogs
  • Loading branch information
cwensley authored Feb 3, 2022
2 parents a4593db + 01e2b75 commit 28d947e
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Eto.WinForms/Forms/ColorDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public DialogResult ShowDialog(Window parent)
swf.DialogResult result;
if (customColors != null) Control.CustomColors = customColors;

if (parent?.HasFocus == false)
parent.Focus();

if (parent != null)
result = Control.ShowDialog(parent.GetContainerControl());
else
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.WinForms/Forms/FontDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public Font Font

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

var result = Control.ShowDialog();
if (result == swf.DialogResult.OK)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Eto.WinForms/Forms/MessageBoxHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public class MessageBoxHandler : WidgetHandler<Widget>, MessageBox.IHandler

public DialogResult ShowDialog(Control parent)
{
var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null);
var parentWindow = parent?.ParentWindow;
if (parentWindow?.HasFocus == false)
parentWindow.Focus();

var caption = Caption ?? parentWindow?.Title;
swf.Control c = (parent == null) ? null : (swf.Control)parent.ControlObject;
swf.DialogResult result = swf.MessageBox.Show(c, Text, caption, Convert(Buttons), Convert(Type), Convert(DefaultButton, Buttons));
return result.ToEto();
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.WinForms/Forms/Printing/PrintDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public PrintDialogHandler()

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

swf.DialogResult result;

Control.PrinterSettings = _printSettings.ToSD();
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.WinForms/Forms/Printing/PrintPreviewDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public PrintSettings PrintSettings

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

swf.DialogResult result;
Control.Document = PrintDocumentHandler.GetControl(Document);

Expand Down
3 changes: 3 additions & 0 deletions src/Eto.WinForms/Forms/SelectFolderDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public SelectFolderDialogHandler ()

public DialogResult ShowDialog (Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

SWF.DialogResult dr;
if (parent != null) dr = Control.ShowDialog((SWF.IWin32Window)parent.ControlObject);
else dr = Control.ShowDialog();
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.WinForms/Forms/WindowsFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public string Title

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

SetFilters();

swf.DialogResult dr;
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Wpf/Forms/ColorDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public DialogResult ShowDialog(Window parent)
{
if (parent != null)
{
if (!parent.HasFocus)
parent.Focus();
var owner = parent.ControlObject as sw.Window;
Control.Owner = owner;
Control.WindowStartupLocation = sw.WindowStartupLocation.CenterOwner;
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Wpf/Forms/FontDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public DialogResult ShowDialog(Window parent)
{
if (parent != null)
{
if (!parent.HasFocus)
parent.Focus();
var owner = parent.ControlObject as sw.Window;
Control.Owner = owner;
Control.WindowStartupLocation = sw.WindowStartupLocation.CenterOwner;
Expand Down
6 changes: 5 additions & 1 deletion src/Eto.Wpf/Forms/MessageBoxHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public DialogResult ShowDialog(Control parent)
{
using (var visualStyles = new EnableThemingInScope(ApplicationHandler.EnableVisualStyles))
{
var parentWindow = parent?.ParentWindow;
if (parentWindow?.HasFocus == false)
parentWindow.Focus();

var element = parent == null ? null : parent.GetContainerControl();
var window = element == null ? null : element.GetVisualParent<sw.Window>();
sw.MessageBoxResult result;
var buttons = Convert(Buttons);
var defaultButton = Convert(DefaultButton, Buttons);
var icon = Convert(Type);
var caption = Caption ?? ((parent != null && parent.ParentWindow != null) ? parent.ParentWindow.Title : null);
var caption = Caption ?? parentWindow?.Title;
if (window != null) result = WpfMessageBox.Show(window, Text, caption, buttons, icon, defaultButton);
else result = WpfMessageBox.Show(Text, caption, buttons, icon, defaultButton);
WpfFrameworkElementHelper.ShouldCaptureMouse = false;
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.Wpf/Forms/Printing/PrintDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public PrintDialogHandler()

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

Control.SetEtoSettings(settings);
var result = Control.ShowDialog();
WpfFrameworkElementHelper.ShouldCaptureMouse = false;
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.Wpf/Forms/Printing/PrintPreviewDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ protected override void Initialize()

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

var print = new swc.PrintDialog();
print.SetEtoSettings(PrintSettings);
Control.Owner = parent?.ToNative();
Expand Down
5 changes: 4 additions & 1 deletion src/Eto.Wpf/Forms/SelectFolderDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public SelectFolderDialogHandler ()

public DialogResult ShowDialog (Window parent)
{
var dr = Control.ShowDialog ();
if (parent?.HasFocus == false)
parent.Focus();

var dr = Control.ShowDialog();
WpfFrameworkElementHelper.ShouldCaptureMouse = false;
return dr == swf.DialogResult.OK ? DialogResult.Ok : DialogResult.Cancel;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Eto.Wpf/Forms/VistaSelectFolderDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public VistaSelectFolderDialogHandler()

public DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();

#if WINFORMS
// use reflection since adding a parameter requires us to reference PresentationFramework which we don't want in winforms
cp.CommonFileDialogResult result;
Expand Down
2 changes: 2 additions & 0 deletions src/Eto.Wpf/Forms/WpfFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ from ex in f.Extensions

public override DialogResult ShowDialog(Window parent)
{
if (parent?.HasFocus == false)
parent.Focus();
SetFilters();
return base.ShowDialog(parent);
}
Expand Down

0 comments on commit 28d947e

Please sign in to comment.