winex11.drv: send WM_MOUSEACTIVATE before closing a window

Lei Zhang thestig at google.com
Fri Jun 15 05:06:15 CDT 2007


Hi,

On Windows, clicking the close button generates a WM_MOUSEACTIVATE
notification. Applications with custom window procedures can choose to
ignore the close button if they wished to. This patch implements that
behavior.
-------------- next part --------------
From c06457c244bfa8952377aa06a75cde1d77aee7a1 Mon Sep 17 00:00:00 2001
From: Lei Zhang <thestig at google.com>
Date: Fri, 15 Jun 2007 02:56:44 -0700
Subject: [PATCH] winex11.drv: send WM_MOUSEACTIVATE before closing a window

---
 dlls/winex11.drv/event.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/dlls/winex11.drv/event.c b/dlls/winex11.drv/event.c
index e3047fd..d5520c6 100644
--- a/dlls/winex11.drv/event.c
+++ b/dlls/winex11.drv/event.c
@@ -396,6 +396,7 @@ static void handle_wm_protocols( HWND hw
         if (IsWindowEnabled(hwnd))
         {
             HMENU hSysMenu;
+            BOOL close = TRUE;
 
             if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return;
             hSysMenu = GetSystemMenu(hwnd, FALSE);
@@ -405,7 +406,26 @@ static void handle_wm_protocols( HWND hw
                 if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
                     return;
             }
-            PostMessageW( hwnd, WM_X11DRV_DELETE_WINDOW, 0, 0 );
+
+            if (GetFocus() != hwnd)
+            {
+                LRESULT ma;
+
+                /* simulate a mouse click on the caption to find out
+                 * whether the window wants to be activated */
+                ma = SendMessageW( hwnd, WM_MOUSEACTIVATE,
+                                   (WPARAM)GetAncestor( hwnd, GA_ROOT ),
+                                   MAKELONG(HTCAPTION,WM_LBUTTONDOWN) );
+                if (ma == MA_NOACTIVATEANDEAT || ma == MA_ACTIVATEANDEAT)
+                    close = FALSE;
+                if (ma == MA_ACTIVATE || ma == MA_ACTIVATEANDEAT)
+                {
+                    Time event_time = (Time)event->data.l[1];
+                    set_focus( hwnd, event_time );
+                }
+            }
+            if (close)
+                PostMessageW( hwnd, WM_X11DRV_DELETE_WINDOW, 0, 0 );
         }
     }
     else if (protocol == x11drv_atom(WM_TAKE_FOCUS))
-- 
1.4.2.1


More information about the wine-patches mailing list