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
23 * questions.
24 */
25
26 package sun.lwawt.macosx;
27
28 import java.awt.*;
29 import java.awt.Dialog.ModalityType;
30 import java.awt.event.*;
31 import java.awt.peer.WindowPeer;
32 import java.beans.*;
33 import java.lang.reflect.InvocationTargetException;
34
35 import javax.swing.*;
36
37 import sun.awt.*;
38 import sun.awt.AWTAccessor.ComponentAccessor;
39 import sun.java2d.SurfaceData;
40 import sun.java2d.opengl.CGLSurfaceData;
41 import sun.lwawt.*;
42 import sun.util.logging.PlatformLogger;
43
44 import com.apple.laf.*;
45 import com.apple.laf.ClientPropertyApplicator.Property;
46 import com.sun.awt.AWTUtilities;
47
48 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
49 private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
50 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
51 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
52 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
53 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
54 private static native void nativeSetNSWindowLocationByPlatform(long nsWindowPtr);
55 private static native void nativeSetNSWindowStandardFrame(long nsWindowPtr,
56 double x, double y, double w, double h);
57 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
58 private static native void nativePushNSWindowToBack(long nsWindowPtr);
59 private static native void nativePushNSWindowToFront(long nsWindowPtr);
60 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
61 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
62 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
63 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
64 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
65 private static native void nativeSynthesizeMouseEnteredExitedEvents();
66 private static native void nativeDispose(long nsWindowPtr);
192 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
193 }}
194 }) {
195 @SuppressWarnings("deprecation")
196 public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
197 Component root = SwingUtilities.getRoot(p);
198 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
199 if (root == null || acc.getPeer(root) == null) return null;
200 return (CPlatformWindow)((LWWindowPeer)acc.getPeer(root)).getPlatformWindow();
201 }
202 };
203
204 // Bounds of the native widget but in the Java coordinate system.
205 // In order to keep it up-to-date we will update them on
206 // 1) setting native bounds via nativeSetBounds() call
207 // 2) getting notification from the native level via deliverMoveResizeEvent()
208 private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
209 private volatile boolean isFullScreenMode;
210 private boolean isFullScreenAnimationOn;
211
212 private Window target;
213 private LWWindowPeer peer;
214 protected CPlatformView contentView;
215 protected CPlatformWindow owner;
216 protected boolean visible = false; // visibility status from native perspective
217 private boolean undecorated; // initialized in getInitialStyleBits()
218 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
219 private CPlatformResponder responder;
220
221 public CPlatformWindow() {
222 super(0, true);
223 }
224
225 /*
226 * Delegate initialization (create native window and all the
227 * related resources).
228 */
229 @Override // PlatformWindow
230 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
231 initializeBase(_target, _peer, _owner, new CPlatformView());
240 Rectangle bounds;
241 if (!IS(DECORATED, styleBits)) {
242 // For undecorated frames the move/resize event does not come if the frame is centered on the screen
243 // so we need to set a stub location to force an initial move/resize. Real bounds would be set later.
244 bounds = new Rectangle(0, 0, 1, 1);
245 } else {
246 bounds = _peer.constrainBounds(_target.getBounds());
247 }
248 final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(),
249 ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height);
250 setPtr(nativeWindowPtr);
251
252 if (target instanceof javax.swing.RootPaneContainer) {
253 final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
254 if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
255 public void propertyChange(final PropertyChangeEvent evt) {
256 CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
257 rootpane.removePropertyChangeListener("ancestor", this);
258 }
259 });
260 }
261
262 validateSurface();
263 }
264
265 protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
266 this.peer = peer;
267 this.target = target;
268 if (owner instanceof CPlatformWindow) {
269 this.owner = (CPlatformWindow)owner;
270 }
271 this.contentView = view;
272 }
273
274 protected CPlatformResponder createPlatformResponder() {
275 return new CPlatformResponder(peer, false);
276 }
277
278 protected CPlatformView createContentView() {
279 return new CPlatformView();
414
415 private native void _toggleFullScreenMode(final long model);
416
417 public void toggleFullScreen() {
418 _toggleFullScreenMode(getNSWindowPtr());
419 }
420
421 @Override // PlatformWindow
422 public void setMenuBar(MenuBar mb) {
423 final long nsWindowPtr = getNSWindowPtr();
424 CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
425 if (mbPeer != null) {
426 nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel());
427 } else {
428 nativeSetNSWindowMenuBar(nsWindowPtr, 0);
429 }
430 }
431
432 @Override // PlatformWindow
433 public void dispose() {
434 contentView.dispose();
435 nativeDispose(getNSWindowPtr());
436 CPlatformWindow.super.dispose();
437 }
438
439 @Override // PlatformWindow
440 public FontMetrics getFontMetrics(Font f) {
441 // TODO: not implemented
442 (new RuntimeException("unimplemented")).printStackTrace();
443 return null;
444 }
445
446 @Override // PlatformWindow
447 public Insets getInsets() {
448 return nativeGetNSWindowInsets(getNSWindowPtr());
449 }
450
451 @Override // PlatformWindow
452 public Point getLocationOnScreen() {
453 return new Point(nativeBounds.x, nativeBounds.y);
662 final long nsWindowPtr = getNSWindowPtr();
663 nativePushNSWindowToBack(nsWindowPtr);
664 }
665
666 @Override // PlatformWindow
667 public void toFront() {
668 final long nsWindowPtr = getNSWindowPtr();
669 LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
670 Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
671 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
672 if( w != null && acc.getPeer(w) != null
673 && ((LWWindowPeer)acc.getPeer(w)).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME
674 && !lwcToolkit.isApplicationActive()) {
675 lwcToolkit.activateApplicationIgnoringOtherApps();
676 }
677 updateFocusabilityForAutoRequestFocus(false);
678 nativePushNSWindowToFront(nsWindowPtr);
679 updateFocusabilityForAutoRequestFocus(true);
680 }
681
682 @Override
683 public void setResizable(final boolean resizable) {
684 setStyleBits(RESIZABLE, resizable);
685 }
686
687 @Override
688 public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
689 nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH);
690 }
691
692 @Override
693 public boolean rejectFocusRequest(FocusEvent.Cause cause) {
694 // Cross-app activation requests are not allowed.
695 if (cause != FocusEvent.Cause.MOUSE_EVENT &&
696 !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
697 {
698 focusLogger.fine("the app is inactive, so the request is rejected");
699 return true;
700 }
701 return false;
702 }
703
704 @Override
|
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
23 * questions.
24 */
25
26 package sun.lwawt.macosx;
27
28 import com.apple.eawt.FullScreenAdapter;
29 import com.apple.eawt.FullScreenUtilities;
30 import com.apple.eawt.event.FullScreenEvent;
31 import java.awt.*;
32 import java.awt.Dialog.ModalityType;
33 import java.awt.event.*;
34 import java.beans.*;
35 import java.lang.reflect.InvocationTargetException;
36
37 import javax.swing.*;
38
39 import sun.awt.*;
40 import sun.awt.AWTAccessor.ComponentAccessor;
41 import sun.java2d.SurfaceData;
42 import sun.java2d.opengl.CGLSurfaceData;
43 import sun.lwawt.*;
44 import sun.util.logging.PlatformLogger;
45
46 import com.apple.laf.*;
47 import com.apple.laf.ClientPropertyApplicator.Property;
48 import com.sun.awt.AWTUtilities;
49 import sun.lwawt.LWWindowPeer.PeerType;
50
51 public class CPlatformWindow extends CFRetainedResource implements PlatformWindow {
52 private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h);
53 private static native void nativeSetNSWindowStyleBits(long nsWindowPtr, int mask, int data);
54 private static native void nativeSetNSWindowMenuBar(long nsWindowPtr, long menuBarPtr);
55 private static native Insets nativeGetNSWindowInsets(long nsWindowPtr);
56 private static native void nativeSetNSWindowBounds(long nsWindowPtr, double x, double y, double w, double h);
57 private static native void nativeSetNSWindowLocationByPlatform(long nsWindowPtr);
58 private static native void nativeSetNSWindowStandardFrame(long nsWindowPtr,
59 double x, double y, double w, double h);
60 private static native void nativeSetNSWindowMinMax(long nsWindowPtr, double minW, double minH, double maxW, double maxH);
61 private static native void nativePushNSWindowToBack(long nsWindowPtr);
62 private static native void nativePushNSWindowToFront(long nsWindowPtr);
63 private static native void nativeSetNSWindowTitle(long nsWindowPtr, String title);
64 private static native void nativeRevalidateNSWindowShadow(long nsWindowPtr);
65 private static native void nativeSetNSWindowMinimizedIcon(long nsWindowPtr, long nsImage);
66 private static native void nativeSetNSWindowRepresentedFilename(long nsWindowPtr, String representedFilename);
67 private static native void nativeSetEnabled(long nsWindowPtr, boolean isEnabled);
68 private static native void nativeSynthesizeMouseEnteredExitedEvents();
69 private static native void nativeDispose(long nsWindowPtr);
195 nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename);
196 }}
197 }) {
198 @SuppressWarnings("deprecation")
199 public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
200 Component root = SwingUtilities.getRoot(p);
201 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
202 if (root == null || acc.getPeer(root) == null) return null;
203 return (CPlatformWindow)((LWWindowPeer)acc.getPeer(root)).getPlatformWindow();
204 }
205 };
206
207 // Bounds of the native widget but in the Java coordinate system.
208 // In order to keep it up-to-date we will update them on
209 // 1) setting native bounds via nativeSetBounds() call
210 // 2) getting notification from the native level via deliverMoveResizeEvent()
211 private Rectangle nativeBounds = new Rectangle(0, 0, 0, 0);
212 private volatile boolean isFullScreenMode;
213 private boolean isFullScreenAnimationOn;
214
215 private FullScreenAdapter fsa;
216 private volatile boolean isInFullScreen;
217
218 private Window target;
219 private LWWindowPeer peer;
220 protected CPlatformView contentView;
221 protected CPlatformWindow owner;
222 protected boolean visible = false; // visibility status from native perspective
223 private boolean undecorated; // initialized in getInitialStyleBits()
224 private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
225 private CPlatformResponder responder;
226
227 public CPlatformWindow() {
228 super(0, true);
229 }
230
231 /*
232 * Delegate initialization (create native window and all the
233 * related resources).
234 */
235 @Override // PlatformWindow
236 public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) {
237 initializeBase(_target, _peer, _owner, new CPlatformView());
246 Rectangle bounds;
247 if (!IS(DECORATED, styleBits)) {
248 // For undecorated frames the move/resize event does not come if the frame is centered on the screen
249 // so we need to set a stub location to force an initial move/resize. Real bounds would be set later.
250 bounds = new Rectangle(0, 0, 1, 1);
251 } else {
252 bounds = _peer.constrainBounds(_target.getBounds());
253 }
254 final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(),
255 ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height);
256 setPtr(nativeWindowPtr);
257
258 if (target instanceof javax.swing.RootPaneContainer) {
259 final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
260 if (rootpane != null) rootpane.addPropertyChangeListener("ancestor", new PropertyChangeListener() {
261 public void propertyChange(final PropertyChangeEvent evt) {
262 CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane);
263 rootpane.removePropertyChangeListener("ancestor", this);
264 }
265 });
266 if (getPeer().getPeerType() == PeerType.FRAME) {
267 fsa = new FullScreenAdapter() {
268 @Override
269 public void windowExitingFullScreen(FullScreenEvent e) {
270 isInFullScreen = false;
271 }
272
273 @Override
274 public void windowEnteringFullScreen(FullScreenEvent e) {
275 isInFullScreen = true;
276 }
277 };
278
279 FullScreenUtilities.addFullScreenListenerTo(target, fsa);
280
281 if (IS(RESIZABLE, styleBits)) {
282 setCanFullscreen(true);
283 }
284 }
285 }
286
287 validateSurface();
288 }
289
290 protected void initializeBase(Window target, LWWindowPeer peer, PlatformWindow owner, CPlatformView view) {
291 this.peer = peer;
292 this.target = target;
293 if (owner instanceof CPlatformWindow) {
294 this.owner = (CPlatformWindow)owner;
295 }
296 this.contentView = view;
297 }
298
299 protected CPlatformResponder createPlatformResponder() {
300 return new CPlatformResponder(peer, false);
301 }
302
303 protected CPlatformView createContentView() {
304 return new CPlatformView();
439
440 private native void _toggleFullScreenMode(final long model);
441
442 public void toggleFullScreen() {
443 _toggleFullScreenMode(getNSWindowPtr());
444 }
445
446 @Override // PlatformWindow
447 public void setMenuBar(MenuBar mb) {
448 final long nsWindowPtr = getNSWindowPtr();
449 CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
450 if (mbPeer != null) {
451 nativeSetNSWindowMenuBar(nsWindowPtr, mbPeer.getModel());
452 } else {
453 nativeSetNSWindowMenuBar(nsWindowPtr, 0);
454 }
455 }
456
457 @Override // PlatformWindow
458 public void dispose() {
459 if (fsa != null) {
460 FullScreenUtilities.removeFullScreenListenerFrom(target, fsa);
461 fsa = null;
462 }
463 contentView.dispose();
464 nativeDispose(getNSWindowPtr());
465 CPlatformWindow.super.dispose();
466 }
467
468 @Override // PlatformWindow
469 public FontMetrics getFontMetrics(Font f) {
470 // TODO: not implemented
471 (new RuntimeException("unimplemented")).printStackTrace();
472 return null;
473 }
474
475 @Override // PlatformWindow
476 public Insets getInsets() {
477 return nativeGetNSWindowInsets(getNSWindowPtr());
478 }
479
480 @Override // PlatformWindow
481 public Point getLocationOnScreen() {
482 return new Point(nativeBounds.x, nativeBounds.y);
691 final long nsWindowPtr = getNSWindowPtr();
692 nativePushNSWindowToBack(nsWindowPtr);
693 }
694
695 @Override // PlatformWindow
696 public void toFront() {
697 final long nsWindowPtr = getNSWindowPtr();
698 LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
699 Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
700 final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
701 if( w != null && acc.getPeer(w) != null
702 && ((LWWindowPeer)acc.getPeer(w)).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME
703 && !lwcToolkit.isApplicationActive()) {
704 lwcToolkit.activateApplicationIgnoringOtherApps();
705 }
706 updateFocusabilityForAutoRequestFocus(false);
707 nativePushNSWindowToFront(nsWindowPtr);
708 updateFocusabilityForAutoRequestFocus(true);
709 }
710
711 private void setCanFullscreen(final boolean canFullScreen) {
712 if (target instanceof RootPaneContainer
713 && getPeer().getPeerType() == PeerType.FRAME) {
714
715 if (isInFullScreen && !canFullScreen) {
716 toggleFullScreen();
717 }
718
719 final RootPaneContainer rpc = (RootPaneContainer) target;
720 rpc.getRootPane().putClientProperty(
721 CPlatformWindow.WINDOW_FULLSCREENABLE, canFullScreen);
722 }
723 }
724
725 @Override
726 public void setResizable(final boolean resizable) {
727 setCanFullscreen(resizable);
728 setStyleBits(RESIZABLE, resizable);
729 setStyleBits(ZOOMABLE, resizable);
730 }
731
732 @Override
733 public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
734 nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH);
735 }
736
737 @Override
738 public boolean rejectFocusRequest(FocusEvent.Cause cause) {
739 // Cross-app activation requests are not allowed.
740 if (cause != FocusEvent.Cause.MOUSE_EVENT &&
741 !((LWCToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
742 {
743 focusLogger.fine("the app is inactive, so the request is rejected");
744 return true;
745 }
746 return false;
747 }
748
749 @Override
|