United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6886678 Clicking on parent JFrame's client area does not switch focus from JWindow to JFrame on Windows
JDK-6886678 : Clicking on parent JFrame's client area does not switch focus from JWindow to JFrame on Windows

Details
Type:
Bug
Submit Date:
2009-09-29
Status:
Closed
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2010-01-13
Component:
client-libs
OS:
windows_vista
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u18
Fixed Versions:
6u18 (b05)

Related Reports
Backport:
Relates:

Sub Tasks

Description
1) Created JWindow with a JFrame parent that is visible.
2) When the program runs, click on JWindow - it gets focus.
3) Now click on JFrame - it should switch focus to the JFrame -
but it does not. This works fine on the mac but does not on Windows.

                                    

Comments
EVALUATION

This works with XAWT.
                                     
2009-09-30
SUGGESTED FIX

--- old/src/solaris/classes/sun/awt/X11/XContentWindow.java	2009-10-28 16:52:34.846922000 +0300
+++ new/src/solaris/classes/sun/awt/X11/XContentWindow.java	2009-10-28 16:52:34.822648000 +0300
@@ -7,6 +7,7 @@
 package sun.awt.X11;
 
 import java.awt.Component;
+import java.awt.Window;
 import java.awt.Rectangle;
 import java.util.logging.*;
 import java.awt.Insets;
@@ -125,6 +126,23 @@
         }
     }
 
+    public void handleButtonPressRelease(XEvent xev) {
+        if (xev.get_type() == ButtonPress) {
+            Window parentWindow = (Window)parentFrame.getTarget();
+            /*
+             * In case the decorated frame is active but not focused
+             * (that is an owned window is currently focused)
+             * it should be made a focused window.
+             * This is needed to focus the frame when it's clicked
+             * in an empty spot of its content area. See 6886678.
+             */
+            if (parentWindow != null && parentWindow.isActive() && !parentWindow.isFocused()) {
+                parentFrame.requestWindowFocus();
+            }
+        }
+        super.handleButtonPressRelease(xev);
+    }
+
     void purgeIconifiedExposeEvents() {
         for (SavedExposeEvent evt : iconifiedExposeEvents) {
             super.handleExposeEvent(evt.target, evt.x, evt.y, evt.w, evt.h);
--- old/src/windows/native/sun/windows/awt_Frame.cpp	2009-10-28 16:52:35.560161000 +0300
+++ new/src/windows/native/sun/windows/awt_Frame.cpp	2009-10-28 16:52:35.512674000 +0300
@@ -1038,9 +1038,25 @@
 // EmbeddedFrame focus stuff
 ////////////////////////////
 
-void AwtFrame::ActivateEmbeddedFrameOnMouseDown()
+
+void AwtFrame::ActivateFrameOnMouseDown()
 {
-    ActivateEmbeddedFrameHelper(AwtComponent::GetFocusedWindow());
+    if (IsEmbeddedFrame()) {
+        ActivateEmbeddedFrameHelper(AwtComponent::GetFocusedWindow());
+    } else {
+        /*
+         * In case the frame is active but not focused
+         * (that is an owned window is currently focused)
+         * it should be sent an activating message.
+         * This is needed to focus the frame when it's clicked
+         * in an empty spot of its client area. See 6886678.
+         */
+        if (GetHWnd() == ::GetActiveWindow() &&
+            GetHWnd() != AwtComponent::GetFocusedWindow())
+        {
+            SynthesizeWmActivate(TRUE, AwtComponent::GetFocusedWindow());
+        }
+    }
 }
 
 /*
--- old/src/windows/native/sun/windows/awt_Component.cpp	2009-10-28 16:52:36.696750000 +0300
+++ new/src/windows/native/sun/windows/awt_Component.cpp	2009-10-28 16:52:36.559172000 +0300
@@ -2508,14 +2508,14 @@
     MSG msg;
     InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y);
 
-    /*
-     * Activate EmbeddedFrame if applicable. It should be done
-     * before the MOUSE_PRESSED event (posted below) will trigger
-     * WM_SETFOCUS (when it's back to the native code) on the component.
-     */
     AwtWindow *toplevel = GetContainer();
-    if (toplevel && toplevel->IsEmbeddedFrame()) {
-        ((AwtFrame*)toplevel)->ActivateEmbeddedFrameOnMouseDown();
+    if (toplevel && !toplevel->IsSimpleWindow()) {
+        /*
+         * Activate the frame if applicable. It should be done
+         * before the MOUSE_PRESSED event (posted below) will trigger
+         * WM_SETFOCUS (when it's back to the native code) on the component.
+         */
+        ((AwtFrame*)toplevel)->ActivateFrameOnMouseDown();
     }
 
     SendMouseEvent(java_awt_event_MouseEvent_MOUSE_PRESSED, now, x, y,
--- old/src/windows/native/sun/windows/awt_Frame.h	2009-10-28 16:52:38.596600000 +0300
+++ new/src/windows/native/sun/windows/awt_Frame.h	2009-10-28 16:52:38.571370000 +0300
@@ -119,7 +119,7 @@
 
     void SynthesizeWmActivate(BOOL doActivate, HWND opposite);
 
-    void ActivateEmbeddedFrameOnMouseDown();
+    void ActivateFrameOnMouseDown();
     BOOL ActivateEmbeddedFrameOnSetFocus(HWND hWndLostFocus);
     void DeactivateEmbeddedFrameOnKillFocus(HWND hWndGotFocus);
     BOOL ActivateEmbeddedFrameHelper(HWND oppositeToplevelHWnd);
                                     
2009-10-28
EVALUATION

It works with XAWT in jdk7, but not in jdk6... So, we have to fix it for both the toolkits.
                                     
2009-10-28



Hardware and Software, Engineered to Work Together