From 33df1564444bd3f32d44f6db541d946c66f4f3d9 Mon Sep 17 00:00:00 2001 From: "Serg V. Zhdanovskih (Norseman)" Date: Mon, 29 Jan 2024 22:00:04 +0300 Subject: [PATCH] Unsuccessful attempt to resolve the dialogs issue on Win7 (#504) --- projects/GKCore/GKCore/AppHost.cs | 4 ++- projects/GKCore/GKCore/SysUtils.cs | 9 +++++-- .../GEDKeeper3/GKUI/Platform/EtoAppHost.cs | 5 ---- .../GKComponents/GKUI/Components/UIHelper.cs | 26 ++++++++++++++----- .../GKComponents/GKUI/Forms/CommonForm.cs | 15 ++++++++--- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/projects/GKCore/GKCore/AppHost.cs b/projects/GKCore/GKCore/AppHost.cs index e10d6ab95..2c8ffb4e2 100644 --- a/projects/GKCore/GKCore/AppHost.cs +++ b/projects/GKCore/GKCore/AppHost.cs @@ -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". * @@ -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 diff --git a/projects/GKCore/GKCore/SysUtils.cs b/projects/GKCore/GKCore/SysUtils.cs index 8fb7019eb..3120f1d8a 100644 --- a/projects/GKCore/GKCore/SysUtils.cs +++ b/projects/GKCore/GKCore/SysUtils.cs @@ -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". * @@ -67,6 +67,7 @@ public enum OSType Windows8, Windows81, Windows10, + Windows11, } public static class SysUtils @@ -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; diff --git a/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs b/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs index eaed580a7..bd2338872 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs +++ b/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs @@ -193,17 +193,12 @@ public override async Task 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; } diff --git a/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs b/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs index 706cc4597..6da04e2d2 100644 --- a/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs +++ b/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs @@ -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". * @@ -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); } } diff --git a/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs b/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs index 4d899dee6..7531cfed0 100644 --- a/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs +++ b/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs @@ -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". * @@ -26,6 +26,7 @@ using GKCore; using GKCore.Design; using GKCore.Interfaces; +using GKUI.Components; using GKUI.Themes; namespace GKUI.Forms @@ -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() {