1 /*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
215 }) {
216 @SuppressWarnings("deprecation")
217 public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
218 Component root = SwingUtilities.getRoot(p);
219 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
220 if (root == null || acc.getPeer(root) == null) return null;
221 return (CPlatformWindow)((LWWindowPeer)acc.getPeer(root)).getPlatformWindow();
222 }
223 };
224
225 // Bounds of the native widget but in the Java coordinate system.
226 // In order to keep it up-to-date we will update them on
227 // 1) setting native bounds via nativeSetBounds() call
228 // 2) getting notification from the native level via deliverMoveResizeEvent()
229 private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
230 private volatile boolean isFullScreenMode;
231 private boolean isFullScreenAnimationOn;
232
233 private volatile boolean isInFullScreen;
234 private volatile boolean isIconifyAnimationActive;
235
236 private Window target;
237 private LWWindowPeer peer;
238 protected CPlatformView contentView;
239 protected CPlatformWindow owner;
240 protected boolean visible = false; // visibility status from native perspective
241 private boolean undecorated; // initialized in getInitialStyleBits()
242 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
243 private CPlatformResponder responder;
244
245 public CPlatformWindow() {
246 super(0, true);
247 }
248
249 /*
250 * Delegate initialization (create native window and all the
251 * related resources).
252 */
253 @Override // PlatformWindow
254 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
489 // TODO: not implemented
490 return null;
491 }
492
493 @Override // PlatformWindow
494 public SurfaceData replaceSurfaceData() {
495 return contentView.replaceSurfaceData();
496 }
497
498 @Override // PlatformWindow
499 public void setBounds(int x, int y, int w, int h) {
500 nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
501 }
502
503 public void setMaximizedBounds(int x, int y, int w, int h) {
504 nativeSetNSWindowStandardFrame(getNSWindowPtr(), x, y, w, h);
505 }
506
507 private boolean isMaximized() {
508 return undecorated ? this.normalBounds != null
509 : CWrapper.NSWindow.isZoomed(getNSWindowPtr());
510 }
511
512 private void maximize() {
513 if (peer == null || isMaximized()) {
514 return;
515 }
516 if (!undecorated) {
517 CWrapper.NSWindow.zoom(getNSWindowPtr());
518 } else {
519 deliverZoom(true);
520
521 // We need an up to date size of the peer, so we flush the native events
522 // to be sure that there are no setBounds requests in the queue.
523 LWCToolkit.flushNativeSelectors();
524 this.normalBounds = peer.getBounds();
525 Rectangle maximizedBounds = peer.getMaximizedBounds();
526 setBounds(maximizedBounds.x, maximizedBounds.y,
527 maximizedBounds.width, maximizedBounds.height);
528 }
529 }
957 }
958 return nativePeer;
959 }
960
961 /*************************************************************
962 * Callbacks from the AWTWindow and AWTView objc classes.
963 *************************************************************/
964 private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite){
965 // Fix for 7150349: ingore "gained" notifications when the app is inactive.
966 if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
967 focusLogger.fine("the app is inactive, so the notification is ignored");
968 return;
969 }
970
971 LWWindowPeer oppositePeer = (opposite == null)? null : opposite.getPeer();
972 responder.handleWindowFocusEvent(gained, oppositePeer);
973 }
974
975 protected void deliverMoveResizeEvent(int x, int y, int width, int height,
976 boolean byUser) {
977 checkZoom();
978
979 final Rectangle oldB = nativeBounds;
980 nativeBounds = new Rectangle(x, y, width, height);
981 if (peer != null) {
982 peer.notifyReshape(x, y, width, height);
983 // System-dependent appearance optimization.
984 if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
985 || isFullScreenAnimationOn) {
986 flushBuffers();
987 }
988 }
989 }
990
991 private void deliverWindowClosingEvent() {
992 if (peer != null && peer.getBlocker() == null) {
993 peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
994 }
995 }
996
|
1 /*
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
215 }) {
216 @SuppressWarnings("deprecation")
217 public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
218 Component root = SwingUtilities.getRoot(p);
219 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
220 if (root == null || acc.getPeer(root) == null) return null;
221 return (CPlatformWindow)((LWWindowPeer)acc.getPeer(root)).getPlatformWindow();
222 }
223 };
224
225 // Bounds of the native widget but in the Java coordinate system.
226 // In order to keep it up-to-date we will update them on
227 // 1) setting native bounds via nativeSetBounds() call
228 // 2) getting notification from the native level via deliverMoveResizeEvent()
229 private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
230 private volatile boolean isFullScreenMode;
231 private boolean isFullScreenAnimationOn;
232
233 private volatile boolean isInFullScreen;
234 private volatile boolean isIconifyAnimationActive;
235 private volatile boolean isZoomed;
236
237 private Window target;
238 private LWWindowPeer peer;
239 protected CPlatformView contentView;
240 protected CPlatformWindow owner;
241 protected boolean visible = false; // visibility status from native perspective
242 private boolean undecorated; // initialized in getInitialStyleBits()
243 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
244 private CPlatformResponder responder;
245
246 public CPlatformWindow() {
247 super(0, true);
248 }
249
250 /*
251 * Delegate initialization (create native window and all the
252 * related resources).
253 */
254 @Override // PlatformWindow
255 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
490 // TODO: not implemented
491 return null;
492 }
493
494 @Override // PlatformWindow
495 public SurfaceData replaceSurfaceData() {
496 return contentView.replaceSurfaceData();
497 }
498
499 @Override // PlatformWindow
500 public void setBounds(int x, int y, int w, int h) {
501 nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
502 }
503
504 public void setMaximizedBounds(int x, int y, int w, int h) {
505 nativeSetNSWindowStandardFrame(getNSWindowPtr(), x, y, w, h);
506 }
507
508 private boolean isMaximized() {
509 return undecorated ? this.normalBounds != null
510 : isZoomed;
511 }
512
513 private void maximize() {
514 if (peer == null || isMaximized()) {
515 return;
516 }
517 if (!undecorated) {
518 CWrapper.NSWindow.zoom(getNSWindowPtr());
519 } else {
520 deliverZoom(true);
521
522 // We need an up to date size of the peer, so we flush the native events
523 // to be sure that there are no setBounds requests in the queue.
524 LWCToolkit.flushNativeSelectors();
525 this.normalBounds = peer.getBounds();
526 Rectangle maximizedBounds = peer.getMaximizedBounds();
527 setBounds(maximizedBounds.x, maximizedBounds.y,
528 maximizedBounds.width, maximizedBounds.height);
529 }
530 }
958 }
959 return nativePeer;
960 }
961
962 /*************************************************************
963 * Callbacks from the AWTWindow and AWTView objc classes.
964 *************************************************************/
965 private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite){
966 // Fix for 7150349: ingore "gained" notifications when the app is inactive.
967 if (gained && !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive()) {
968 focusLogger.fine("the app is inactive, so the notification is ignored");
969 return;
970 }
971
972 LWWindowPeer oppositePeer = (opposite == null)? null : opposite.getPeer();
973 responder.handleWindowFocusEvent(gained, oppositePeer);
974 }
975
976 protected void deliverMoveResizeEvent(int x, int y, int width, int height,
977 boolean byUser) {
978 isZoomed = CWrapper.NSWindow.isZoomed(getNSWindowPtr());
979 checkZoom();
980
981 final Rectangle oldB = nativeBounds;
982 nativeBounds = new Rectangle(x, y, width, height);
983 if (peer != null) {
984 peer.notifyReshape(x, y, width, height);
985 // System-dependent appearance optimization.
986 if ((byUser && !oldB.getSize().equals(nativeBounds.getSize()))
987 || isFullScreenAnimationOn) {
988 flushBuffers();
989 }
990 }
991 }
992
993 private void deliverWindowClosingEvent() {
994 if (peer != null && peer.getBlocker() == null) {
995 peer.postEvent(new WindowEvent(target, WindowEvent.WINDOW_CLOSING));
996 }
997 }
998
|