Skip to content

Commit

Permalink
Unsuccessful attempt to resolve the dialogs issue on Win7 (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Jan 29, 2024
1 parent c4edb6a commit 33df156
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
4 changes: 3 additions & 1 deletion projects/GKCore/GKCore/AppHost.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -118,6 +118,8 @@ private void AutosaveTimer_Tick(object sender, EventArgs e)
public static void LogSysInfo()
{
try {
Logger.WriteInfo("OS Version: " + SysUtils.GetOSType().ToString());

#if MONO
Logger.WriteInfo("Mono Version: " + SysUtils.GetMonoVersion());
#endif
Expand Down
9 changes: 7 additions & 2 deletions projects/GKCore/GKCore/SysUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -67,6 +67,7 @@ public enum OSType
Windows8,
Windows81,
Windows10,
Windows11,
}

public static class SysUtils
Expand Down Expand Up @@ -317,7 +318,11 @@ public static OSType GetOSType()
}
break;
case 10:
result = OSType.Windows10;
if (osVersion.Version.Build >= 22000) {
result = OSType.Windows11;
} else {
result = OSType.Windows10;
}
break;
}
break;
Expand Down
5 changes: 0 additions & 5 deletions projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,12 @@ public override async Task<bool> ShowModalAsync(ICommonDialog dialog, IView owne
if (efModal == null) return false;

//Window activeWin = GetActiveForm() as Window;
//Console.WriteLine((owner == null) ? "null" : owner.ToString());

/*if (keepModeless) {
#if OS_MSWIN
//NativeMethods.PostMessage(mainHandle, NativeMethods.WM_KEEPMODELESS, IntPtr.Zero, IntPtr.Zero);
#endif
}*/

// for EtoForms works without this (Win10)
//UIHelper.CenterFormByParent((Window)form, mainHandle);

efModal.ShowModal(owner as Control);
return await efModal.DialogResultTask;
}
Expand Down
26 changes: 19 additions & 7 deletions projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih, Ruslan Garipov.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih, Ruslan Garipov.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -140,16 +140,28 @@ public static void CenterFormByParent(Window form, Rectangle parentRect)
{
if (form == null) return;

//form.StartPosition = FormStartPosition.Manual;

// Center the new window on a monitor, where the parent window
// is located.
// Center the new window on a monitor, where the parent window is located.
Screen screen = Screen.FromRectangle(parentRect);
if (screen != null) {
var workArea = screen.WorkingArea;

int fx = (int)workArea.Left + (((int)workArea.Width - form.Width) >> 1);
int fy = (int)workArea.Top + (((int)workArea.Height - form.Height) >> 1);
//Logger.WriteInfo(string.Format("ParentRect: {0} - {1} - {2} - {3}", parentRect.Left, parentRect.Top, parentRect.Width, parentRect.Height));
//Logger.WriteInfo(string.Format("Dlg: {0} - {1}", form.Width, form.Height));

int fx = (int)parentRect.Left + ((int)(parentRect.Width - form.Width) / 2);
int fy = (int)parentRect.Top + ((int)(parentRect.Height - form.Height) / 2);

//Logger.WriteInfo(string.Format("Loc: {0} - {1}", fx, fy));

if (!workArea.Contains(fx, fy)) {
//Logger.WriteInfo("not contains");

fx = (int)workArea.Left + ((int)(workArea.Width - form.Width) / 2);
fy = (int)workArea.Top + ((int)(workArea.Height - form.Height) / 2);

//Logger.WriteInfo(string.Format("Loc: {0} - {1}", fx, fy));
}

form.Location = new Point(fx, fy);
}
}
Expand Down
15 changes: 11 additions & 4 deletions projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand All @@ -26,6 +26,7 @@
using GKCore;
using GKCore.Design;
using GKCore.Interfaces;
using GKUI.Components;
using GKUI.Themes;

namespace GKUI.Forms
Expand Down Expand Up @@ -273,14 +274,20 @@ protected override void OnLoad(EventArgs e)
ApplyTheme();
}

/*protected override void OnShown(EventArgs e)
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
//BringToFront();

/*BringToFront();
if (ParentWindow != null) {
ParentWindow.SendToBack();
}*/

// Only for Windows7
if (SysUtils.GetOSType() < OSType.Windows8 && Owner != null) {
UIHelper.CenterFormByParent(this, Owner.Bounds);
}
}*/
}

public virtual void ApplyTheme()
{
Expand Down

0 comments on commit 33df156

Please sign in to comment.