]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Disable GUI parent window when dialog is open.
authorToni Wilen <twilen@winuae.net>
Fri, 15 Dec 2023 20:09:43 +0000 (22:09 +0200)
committerToni Wilen <twilen@winuae.net>
Fri, 15 Dec 2023 20:09:43 +0000 (22:09 +0200)
od-win32/win32gui.cpp

index 974f29dff626409b96afe3759df6a6a7959b3046..b1871eb54fa9fbab5ca68b65f3d1673561397000 100644 (file)
@@ -23153,6 +23153,47 @@ HWND CustomCreateDialog(struct newresource **resp, int templ, HWND hDlg, DLGPROC
        return h;
 }
 
+static void enableparent(HWND parent)
+{
+       if (parent) {
+               EnableWindow(parent, TRUE);
+       }
+}
+
+static HWND disableparent(HWND owner)
+{
+       HWND parent = NULL;
+       HWND disabled_owner = NULL;
+       /*
+        * Owner needs to be top level window. We need to duplicate the logic from server,
+        * because we need to disable it before creating dialog window. Note that we do that
+        * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
+        * Windows does.
+        */
+       while ((GetWindowLongW(owner, GWL_STYLE) & (WS_POPUP | WS_CHILD)) == WS_CHILD) {
+               parent = GetParent(owner);
+               if (!parent || parent == GetDesktopWindow())
+                       break;
+               owner = parent;
+       }
+       if (!parent)
+               parent = GetAncestor(owner, GA_ROOT);
+       if (parent)
+       {
+               owner = parent;
+               if (IsWindowEnabled(owner))
+               {
+                       HWND captured = NULL;
+                       disabled_owner = owner;
+                       EnableWindow(disabled_owner, FALSE);
+                       captured = GetCapture();
+                       if (captured)
+                               SendMessageW(captured, WM_CANCELMODE, 0, 0);
+               }
+       }
+       return disabled_owner;
+}
+
 int CustomCreateDialogBox(int templ, HWND hDlg, DLGPROC proc)
 {
        struct newresource *res;
@@ -23161,6 +23202,7 @@ int CustomCreateDialogBox(int templ, HWND hDlg, DLGPROC proc)
        if (!hwnd) {
                return 0;
        }
+       HWND owner = disableparent(hDlg);
        customdialogres = res;
        customdialoghwnd = hwnd;
        while (customdialogactive == 1) {
@@ -23170,14 +23212,21 @@ int CustomCreateDialogBox(int templ, HWND hDlg, DLGPROC proc)
                while ((ret = GetMessage(&msg, NULL, 0, 0))) {
                        if (ret == -1)
                                break;
-                       if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) {
+                       if (!IsWindow(hwnd)) {
+                               break;
+                       }
+                       if (!IsDialogMessage(hwnd, &msg)) {
                                TranslateMessage(&msg);
                                DispatchMessage(&msg);
                        }
+                       if (!IsWindow(hwnd)) {
+                               break;
+                       }
                        if (customdialogactive == -1)
                                break;
                }
        }
+       enableparent(owner);
        return customdialogactive;
 }