31 import java.util.List;
32
33 import javax.swing.*;
34
35 import sun.awt.*;
36 import sun.java2d.*;
37 import sun.java2d.loops.Blit;
38 import sun.java2d.loops.CompositeType;
39 import sun.java2d.pipe.Region;
40 import sun.util.logging.PlatformLogger;
41
42 public class LWWindowPeer
43 extends LWContainerPeer<Window, JComponent>
44 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
45 {
46 public static enum PeerType {
47 SIMPLEWINDOW,
48 FRAME,
49 DIALOG,
50 EMBEDDED_FRAME,
51 VIEW_EMBEDDED_FRAME
52 }
53
54 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
55
56 private final PlatformWindow platformWindow;
57
58 // Window bounds reported by the native system (as opposed to
59 // regular bounds inherited from LWComponentPeer which are
60 // requested by user and may haven't been applied yet because
61 // of asynchronous requests to the windowing system)
62 private int sysX;
63 private int sysY;
64 private int sysW;
65 private int sysH;
66
67 private static final int MINIMUM_WIDTH = 1;
68 private static final int MINIMUM_HEIGHT = 1;
69
70 private Insets insets = new Insets(0, 0, 0, 0);
71
1073 owner.skipNextFocusChange = true;
1074
1075 owner.platformWindow.requestWindowFocus();
1076 }
1077
1078 // DKFM will synthesize all the focus/activation events correctly.
1079 changeFocusedWindow(true, opposite);
1080 return true;
1081
1082 // In case the toplevel is active but not focused, change focus directly,
1083 // as requesting native focus on it will not have effect.
1084 } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1085
1086 changeFocusedWindow(true, opposite);
1087 return true;
1088 }
1089
1090 return platformWindow.requestWindowFocus();
1091 }
1092
1093 private boolean focusAllowedFor() {
1094 Window window = getTarget();
1095 // TODO: check if modal blocked
1096 return window.isVisible() && window.isEnabled() && isFocusableWindow();
1097 }
1098
1099 private boolean isFocusableWindow() {
1100 boolean focusable = getTarget().isFocusableWindow();
1101 if (isSimpleWindow()) {
1102 LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
1103 if (ownerPeer == null) {
1104 return false;
1105 }
1106 return focusable && ownerPeer.getTarget().isFocusableWindow();
1107 }
1108 return focusable;
1109 }
1110
1111 public boolean isSimpleWindow() {
1112 Window window = getTarget();
1113 return !(window instanceof Dialog || window instanceof Frame);
1114 }
1115
1116 /*
1117 * Changes focused window on java level.
1118 */
1119 private void changeFocusedWindow(boolean becomesFocused, Window opposite) {
1120 if (focusLog.isLoggable(PlatformLogger.FINE)) {
1121 focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1122 }
1123 if (skipNextFocusChange) {
1124 focusLog.fine("skipping focus change");
1125 skipNextFocusChange = false;
1126 return;
1127 }
1128 if (!isFocusableWindow() && becomesFocused) {
1129 focusLog.fine("the window is not focusable");
1130 return;
1131 }
1132 if (becomesFocused) {
1133 synchronized (getPeerTreeLock()) {
1134 if (blocker != null) {
1135 if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1136 focusLog.finest("the window is blocked by " + blocker);
1137 }
1138 return;
1139 }
1180 }
1181 while (blocker.blocker != null) {
1182 blocker = blocker.blocker;
1183 }
1184 return blocker;
1185 }
1186 }
1187
1188 public void enterFullScreenMode() {
1189 platformWindow.enterFullScreenMode();
1190 }
1191
1192 public void exitFullScreenMode() {
1193 platformWindow.exitFullScreenMode();
1194 }
1195
1196 public long getLayerPtr() {
1197 return getPlatformWindow().getLayerPtr();
1198 }
1199
1200 void grab() {
1201 if (grabbingWindow != null && !isGrabbing()) {
1202 grabbingWindow.ungrab();
1203 }
1204 grabbingWindow = this;
1205 }
1206
1207 final void ungrab(boolean doPost) {
1208 if (isGrabbing()) {
1209 grabbingWindow = null;
1210 if (doPost) {
1211 postEvent(new UngrabEvent(getTarget()));
1212 }
1213 }
1214 }
1215
1216 void ungrab() {
1217 ungrab(true);
1218 }
1219
|
31 import java.util.List;
32
33 import javax.swing.*;
34
35 import sun.awt.*;
36 import sun.java2d.*;
37 import sun.java2d.loops.Blit;
38 import sun.java2d.loops.CompositeType;
39 import sun.java2d.pipe.Region;
40 import sun.util.logging.PlatformLogger;
41
42 public class LWWindowPeer
43 extends LWContainerPeer<Window, JComponent>
44 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
45 {
46 public static enum PeerType {
47 SIMPLEWINDOW,
48 FRAME,
49 DIALOG,
50 EMBEDDED_FRAME,
51 VIEW_EMBEDDED_FRAME,
52 LW_FRAME
53 }
54
55 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
56
57 private final PlatformWindow platformWindow;
58
59 // Window bounds reported by the native system (as opposed to
60 // regular bounds inherited from LWComponentPeer which are
61 // requested by user and may haven't been applied yet because
62 // of asynchronous requests to the windowing system)
63 private int sysX;
64 private int sysY;
65 private int sysW;
66 private int sysH;
67
68 private static final int MINIMUM_WIDTH = 1;
69 private static final int MINIMUM_HEIGHT = 1;
70
71 private Insets insets = new Insets(0, 0, 0, 0);
72
1074 owner.skipNextFocusChange = true;
1075
1076 owner.platformWindow.requestWindowFocus();
1077 }
1078
1079 // DKFM will synthesize all the focus/activation events correctly.
1080 changeFocusedWindow(true, opposite);
1081 return true;
1082
1083 // In case the toplevel is active but not focused, change focus directly,
1084 // as requesting native focus on it will not have effect.
1085 } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1086
1087 changeFocusedWindow(true, opposite);
1088 return true;
1089 }
1090
1091 return platformWindow.requestWindowFocus();
1092 }
1093
1094 protected boolean focusAllowedFor() {
1095 Window window = getTarget();
1096 // TODO: check if modal blocked
1097 return window.isVisible() && window.isEnabled() && isFocusableWindow();
1098 }
1099
1100 private boolean isFocusableWindow() {
1101 boolean focusable = getTarget().isFocusableWindow();
1102 if (isSimpleWindow()) {
1103 LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
1104 if (ownerPeer == null) {
1105 return false;
1106 }
1107 return focusable && ownerPeer.getTarget().isFocusableWindow();
1108 }
1109 return focusable;
1110 }
1111
1112 public boolean isSimpleWindow() {
1113 Window window = getTarget();
1114 return !(window instanceof Dialog || window instanceof Frame);
1115 }
1116
1117 @Override
1118 public void emulateActivation(boolean activate) {
1119 changeFocusedWindow(activate, null);
1120 }
1121
1122 /*
1123 * Changes focused window on java level.
1124 */
1125 protected void changeFocusedWindow(boolean becomesFocused, Window opposite) {
1126 if (focusLog.isLoggable(PlatformLogger.FINE)) {
1127 focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1128 }
1129 if (skipNextFocusChange) {
1130 focusLog.fine("skipping focus change");
1131 skipNextFocusChange = false;
1132 return;
1133 }
1134 if (!isFocusableWindow() && becomesFocused) {
1135 focusLog.fine("the window is not focusable");
1136 return;
1137 }
1138 if (becomesFocused) {
1139 synchronized (getPeerTreeLock()) {
1140 if (blocker != null) {
1141 if (focusLog.isLoggable(PlatformLogger.FINEST)) {
1142 focusLog.finest("the window is blocked by " + blocker);
1143 }
1144 return;
1145 }
1186 }
1187 while (blocker.blocker != null) {
1188 blocker = blocker.blocker;
1189 }
1190 return blocker;
1191 }
1192 }
1193
1194 public void enterFullScreenMode() {
1195 platformWindow.enterFullScreenMode();
1196 }
1197
1198 public void exitFullScreenMode() {
1199 platformWindow.exitFullScreenMode();
1200 }
1201
1202 public long getLayerPtr() {
1203 return getPlatformWindow().getLayerPtr();
1204 }
1205
1206 @Override
1207 public void grabFocus() {
1208 grab();
1209 }
1210
1211 @Override
1212 public void ungrabFocus(boolean postEvent) {
1213 ungrab(postEvent);
1214 }
1215
1216 void grab() {
1217 if (grabbingWindow != null && !isGrabbing()) {
1218 grabbingWindow.ungrab();
1219 }
1220 grabbingWindow = this;
1221 }
1222
1223 final void ungrab(boolean doPost) {
1224 if (isGrabbing()) {
1225 grabbingWindow = null;
1226 if (doPost) {
1227 postEvent(new UngrabEvent(getTarget()));
1228 }
1229 }
1230 }
1231
1232 void ungrab() {
1233 ungrab(true);
1234 }
1235
|