1042 return false; 1043 } 1044 insets = newInsets; 1045 } 1046 return true; 1047 } 1048 1049 public static LWWindowPeer getWindowUnderCursor() { 1050 return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null; 1051 } 1052 1053 public static LWComponentPeer<?, ?> getPeerUnderCursor() { 1054 return lastCommonMouseEventPeer; 1055 } 1056 1057 /* 1058 * Requests platform to set native focus on a frame/dialog. 1059 * In case of a simple window, triggers appropriate java focus change. 1060 */ 1061 public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { 1062 if (focusLog.isLoggable(PlatformLogger.FINE)) { 1063 focusLog.fine("requesting native focus to " + this); 1064 } 1065 1066 if (!focusAllowedFor()) { 1067 focusLog.fine("focus is not allowed"); 1068 return false; 1069 } 1070 1071 if (platformWindow.rejectFocusRequest(cause)) { 1072 return false; 1073 } 1074 1075 Window currentActive = KeyboardFocusManager. 1076 getCurrentKeyboardFocusManager().getActiveWindow(); 1077 1078 Window opposite = LWKeyboardFocusManagerPeer.getInstance(). 1079 getCurrentFocusedWindow(); 1080 1081 // Make the owner active window. 1082 if (isSimpleWindow()) { 1083 LWWindowPeer owner = getOwnerFrameDialog(this); 1084 1085 // If owner is not natively active, request native 1086 // activation on it w/o sending events up to java. 1087 if (owner != null && !owner.platformWindow.isActive()) { 1088 if (focusLog.isLoggable(PlatformLogger.FINE)) { 1089 focusLog.fine("requesting native focus to the owner " + owner); 1090 } 1091 LWWindowPeer currentActivePeer = (currentActive != null ? 1092 (LWWindowPeer)currentActive.getPeer() : null); 1093 1094 // Ensure the opposite is natively active and suppress sending events. 1095 if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) { 1096 if (focusLog.isLoggable(PlatformLogger.FINE)) { 1097 focusLog.fine("the opposite is " + currentActivePeer); 1098 } 1099 currentActivePeer.skipNextFocusChange = true; 1100 } 1101 owner.skipNextFocusChange = true; 1102 1103 owner.platformWindow.requestWindowFocus(); 1104 } 1105 1106 // DKFM will synthesize all the focus/activation events correctly. 1107 changeFocusedWindow(true, opposite); 1108 return true; 1109 1110 // In case the toplevel is active but not focused, change focus directly, 1111 // as requesting native focus on it will not have effect. 1112 } else if (getTarget() == currentActive && !getTarget().hasFocus()) { 1113 1114 changeFocusedWindow(true, opposite); 1115 return true; 1116 } 1133 } 1134 return focusable && ownerPeer.getTarget().isFocusableWindow(); 1135 } 1136 return focusable; 1137 } 1138 1139 public boolean isSimpleWindow() { 1140 Window window = getTarget(); 1141 return !(window instanceof Dialog || window instanceof Frame); 1142 } 1143 1144 @Override 1145 public void emulateActivation(boolean activate) { 1146 changeFocusedWindow(activate, null); 1147 } 1148 1149 /* 1150 * Changes focused window on java level. 1151 */ 1152 protected void changeFocusedWindow(boolean becomesFocused, Window opposite) { 1153 if (focusLog.isLoggable(PlatformLogger.FINE)) { 1154 focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this); 1155 } 1156 if (skipNextFocusChange) { 1157 focusLog.fine("skipping focus change"); 1158 skipNextFocusChange = false; 1159 return; 1160 } 1161 if (!isFocusableWindow() && becomesFocused) { 1162 focusLog.fine("the window is not focusable"); 1163 return; 1164 } 1165 if (becomesFocused) { 1166 synchronized (getPeerTreeLock()) { 1167 if (blocker != null) { 1168 if (focusLog.isLoggable(PlatformLogger.FINEST)) { 1169 focusLog.finest("the window is blocked by " + blocker); 1170 } 1171 return; 1172 } 1173 } 1174 } 1175 1176 // Note, the method is not called: 1177 // - when the opposite (gaining focus) window is an owned/owner window. 1178 // - for a simple window in any case. 1179 if (!becomesFocused && 1180 (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this)) 1181 { 1182 if (focusLog.isLoggable(PlatformLogger.FINE)) { 1183 focusLog.fine("ungrabbing on " + grabbingWindow); 1184 } 1185 // ungrab a simple window if its owner looses activation. 1186 grabbingWindow.ungrab(); 1187 } 1188 1189 KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); 1190 kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null); 1191 1192 int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS; 1193 WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis()); 1194 1195 // TODO: wrap in SequencedEvent 1196 postEvent(windowEvent); 1197 } 1198 1199 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) { 1200 Window owner = (peer != null ? peer.getTarget().getOwner() : null); 1201 while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) { 1202 owner = owner.getOwner(); | 1042 return false; 1043 } 1044 insets = newInsets; 1045 } 1046 return true; 1047 } 1048 1049 public static LWWindowPeer getWindowUnderCursor() { 1050 return lastCommonMouseEventPeer != null ? lastCommonMouseEventPeer.getWindowPeerOrSelf() : null; 1051 } 1052 1053 public static LWComponentPeer<?, ?> getPeerUnderCursor() { 1054 return lastCommonMouseEventPeer; 1055 } 1056 1057 /* 1058 * Requests platform to set native focus on a frame/dialog. 1059 * In case of a simple window, triggers appropriate java focus change. 1060 */ 1061 public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { 1062 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 1063 focusLog.fine("requesting native focus to " + this); 1064 } 1065 1066 if (!focusAllowedFor()) { 1067 focusLog.fine("focus is not allowed"); 1068 return false; 1069 } 1070 1071 if (platformWindow.rejectFocusRequest(cause)) { 1072 return false; 1073 } 1074 1075 Window currentActive = KeyboardFocusManager. 1076 getCurrentKeyboardFocusManager().getActiveWindow(); 1077 1078 Window opposite = LWKeyboardFocusManagerPeer.getInstance(). 1079 getCurrentFocusedWindow(); 1080 1081 // Make the owner active window. 1082 if (isSimpleWindow()) { 1083 LWWindowPeer owner = getOwnerFrameDialog(this); 1084 1085 // If owner is not natively active, request native 1086 // activation on it w/o sending events up to java. 1087 if (owner != null && !owner.platformWindow.isActive()) { 1088 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 1089 focusLog.fine("requesting native focus to the owner " + owner); 1090 } 1091 LWWindowPeer currentActivePeer = (currentActive != null ? 1092 (LWWindowPeer)currentActive.getPeer() : null); 1093 1094 // Ensure the opposite is natively active and suppress sending events. 1095 if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) { 1096 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 1097 focusLog.fine("the opposite is " + currentActivePeer); 1098 } 1099 currentActivePeer.skipNextFocusChange = true; 1100 } 1101 owner.skipNextFocusChange = true; 1102 1103 owner.platformWindow.requestWindowFocus(); 1104 } 1105 1106 // DKFM will synthesize all the focus/activation events correctly. 1107 changeFocusedWindow(true, opposite); 1108 return true; 1109 1110 // In case the toplevel is active but not focused, change focus directly, 1111 // as requesting native focus on it will not have effect. 1112 } else if (getTarget() == currentActive && !getTarget().hasFocus()) { 1113 1114 changeFocusedWindow(true, opposite); 1115 return true; 1116 } 1133 } 1134 return focusable && ownerPeer.getTarget().isFocusableWindow(); 1135 } 1136 return focusable; 1137 } 1138 1139 public boolean isSimpleWindow() { 1140 Window window = getTarget(); 1141 return !(window instanceof Dialog || window instanceof Frame); 1142 } 1143 1144 @Override 1145 public void emulateActivation(boolean activate) { 1146 changeFocusedWindow(activate, null); 1147 } 1148 1149 /* 1150 * Changes focused window on java level. 1151 */ 1152 protected void changeFocusedWindow(boolean becomesFocused, Window opposite) { 1153 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 1154 focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this); 1155 } 1156 if (skipNextFocusChange) { 1157 focusLog.fine("skipping focus change"); 1158 skipNextFocusChange = false; 1159 return; 1160 } 1161 if (!isFocusableWindow() && becomesFocused) { 1162 focusLog.fine("the window is not focusable"); 1163 return; 1164 } 1165 if (becomesFocused) { 1166 synchronized (getPeerTreeLock()) { 1167 if (blocker != null) { 1168 if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) { 1169 focusLog.finest("the window is blocked by " + blocker); 1170 } 1171 return; 1172 } 1173 } 1174 } 1175 1176 // Note, the method is not called: 1177 // - when the opposite (gaining focus) window is an owned/owner window. 1178 // - for a simple window in any case. 1179 if (!becomesFocused && 1180 (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this)) 1181 { 1182 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 1183 focusLog.fine("ungrabbing on " + grabbingWindow); 1184 } 1185 // ungrab a simple window if its owner looses activation. 1186 grabbingWindow.ungrab(); 1187 } 1188 1189 KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); 1190 kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null); 1191 1192 int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS; 1193 WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis()); 1194 1195 // TODO: wrap in SequencedEvent 1196 postEvent(windowEvent); 1197 } 1198 1199 static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) { 1200 Window owner = (peer != null ? peer.getTarget().getOwner() : null); 1201 while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) { 1202 owner = owner.getOwner(); |