提交 7a828a62 编写于 作者: M mcherkas

8165626: Improved window framing

Reviewed-by: serb
上级 35bb0949
...@@ -72,8 +72,7 @@ class _AppDockIconHandler { ...@@ -72,8 +72,7 @@ class _AppDockIconHandler {
public void setDockIconImage(final Image image) { public void setDockIconImage(final Image image) {
try { try {
final CImage cImage = getCImageCreator().createFromImage(image); final CImage cImage = getCImageCreator().createFromImage(image);
final long nsImagePtr = getNSImagePtrFrom(cImage); cImage.execute(_AppDockIconHandler::nativeSetDockIconImage);
nativeSetDockIconImage(nsImagePtr);
} catch (final Throwable e) { } catch (final Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -102,16 +101,4 @@ class _AppDockIconHandler { ...@@ -102,16 +101,4 @@ class _AppDockIconHandler {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
static long getNSImagePtrFrom(final CImage cImage) {
if (cImage == null) return 0;
try {
final Field cImagePtrField = CFRetainedResource.class.getDeclaredField("ptr");
cImagePtrField.setAccessible(true);
return cImagePtrField.getLong(cImage);
} catch (final Throwable e) {
throw new RuntimeException(e);
}
}
} }
...@@ -108,7 +108,7 @@ public class CGLLayer extends CFRetainedResource { ...@@ -108,7 +108,7 @@ public class CGLLayer extends CFRetainedResource {
OGLRenderQueue rq = OGLRenderQueue.getInstance(); OGLRenderQueue rq = OGLRenderQueue.getInstance();
rq.lock(); rq.lock();
try { try {
validate(getPointer(), cglsd); execute(ptr -> validate(ptr, cglsd));
} finally { } finally {
rq.unlock(); rq.unlock();
} }
...@@ -124,7 +124,7 @@ public class CGLLayer extends CFRetainedResource { ...@@ -124,7 +124,7 @@ public class CGLLayer extends CFRetainedResource {
private void setScale(final int _scale) { private void setScale(final int _scale) {
if (scale != _scale) { if (scale != _scale) {
scale = _scale; scale = _scale;
nativeSetScale(getPointer(), scale); execute(ptr -> nativeSetScale(ptr, scale));
} }
} }
...@@ -138,7 +138,7 @@ public class CGLLayer extends CFRetainedResource { ...@@ -138,7 +138,7 @@ public class CGLLayer extends CFRetainedResource {
OGLRenderQueue rq = OGLRenderQueue.getInstance(); OGLRenderQueue rq = OGLRenderQueue.getInstance();
rq.lock(); rq.lock();
try { try {
blitTexture(getPointer()); execute(ptr -> blitTexture(ptr));
} finally { } finally {
rq.unlock(); rq.unlock();
} }
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
package sun.lwawt.macosx; package sun.lwawt.macosx;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/** /**
* Safely holds and disposes of native AppKit resources, using the * Safely holds and disposes of native AppKit resources, using the
* correct AppKit threading and Objective-C GC semantics. * correct AppKit threading and Objective-C GC semantics.
...@@ -36,6 +40,10 @@ public class CFRetainedResource { ...@@ -36,6 +40,10 @@ public class CFRetainedResource {
// TODO this pointer should be private and accessed via CFNativeAction class // TODO this pointer should be private and accessed via CFNativeAction class
protected volatile long ptr; protected volatile long ptr;
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final Lock writeLock = lock.writeLock();
private final Lock readLock = lock.readLock();
/** /**
* @param ptr CFRetained native object pointer * @param ptr CFRetained native object pointer
* @param disposeOnAppKitThread is the object needs to be CFReleased on the main thread * @param disposeOnAppKitThread is the object needs to be CFReleased on the main thread
...@@ -50,21 +58,31 @@ public class CFRetainedResource { ...@@ -50,21 +58,31 @@ public class CFRetainedResource {
* @param ptr CFRetained native object pointer * @param ptr CFRetained native object pointer
*/ */
protected void setPtr(final long ptr) { protected void setPtr(final long ptr) {
synchronized (this) { writeLock.lock();
if (this.ptr != 0) dispose(); try {
if (this.ptr != 0) {
dispose();
}
this.ptr = ptr; this.ptr = ptr;
} finally {
writeLock.unlock();
} }
} }
/** /**
* Manually CFReleases the native resource * Manually CFReleases the native resource.
*/ */
protected void dispose() { protected void dispose() {
long oldPtr = 0L; long oldPtr = 0L;
synchronized (this) { writeLock.lock();
if (ptr == 0) return; try {
if (ptr == 0) {
return;
}
oldPtr = ptr; oldPtr = ptr;
ptr = 0; ptr = 0;
} finally {
writeLock.unlock();
} }
nativeCFRelease(oldPtr, disposeOnAppKitThread); // perform outside of the synchronized block nativeCFRelease(oldPtr, disposeOnAppKitThread); // perform outside of the synchronized block
...@@ -109,10 +127,15 @@ public class CFRetainedResource { ...@@ -109,10 +127,15 @@ public class CFRetainedResource {
* *
* @param action The native operation * @param action The native operation
*/ */
public final synchronized void execute(final CFNativeAction action) { public final void execute(final CFNativeAction action) {
readLock.lock();
try {
if (ptr != 0) { if (ptr != 0) {
action.run(ptr); action.run(ptr);
} }
} finally {
readLock.unlock();
}
} }
/** /**
...@@ -127,10 +150,15 @@ public class CFRetainedResource { ...@@ -127,10 +150,15 @@ public class CFRetainedResource {
* @return result of the native operation, usually the native pointer to * @return result of the native operation, usually the native pointer to
* some other data * some other data
*/ */
final synchronized long executeGet(final CFNativeActionGet action) { final long executeGet(final CFNativeActionGet action) {
readLock.lock();
try {
if (ptr != 0) { if (ptr != 0) {
return action.run(ptr); return action.run(ptr);
} }
} finally {
readLock.unlock();
}
return 0; return 0;
} }
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,7 @@ import java.util.Arrays; ...@@ -33,6 +33,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import sun.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionImage;
import sun.awt.image.MultiResolutionCachedImage; import sun.awt.image.MultiResolutionCachedImage;
import java.util.concurrent.atomic.AtomicReference;
import sun.awt.image.SunWritableRaster; import sun.awt.image.SunWritableRaster;
...@@ -235,15 +236,26 @@ public class CImage extends CFRetainedResource { ...@@ -235,15 +236,26 @@ public class CImage extends CFRetainedResource {
/** @return A MultiResolution image created from nsImagePtr, or null. */ /** @return A MultiResolution image created from nsImagePtr, or null. */
private Image toImage() { private Image toImage() {
if (ptr == 0) return null; if (ptr == 0) {
return null;
}
final Dimension2D size = nativeGetNSImageSize(ptr); AtomicReference<Dimension2D> sizeRef = new AtomicReference<>();
execute(ptr -> {
sizeRef.set(nativeGetNSImageSize(ptr));
});
final Dimension2D size = sizeRef.get();
if (size == null) {
return null;
}
final int w = (int)size.getWidth(); final int w = (int)size.getWidth();
final int h = (int)size.getHeight(); final int h = (int)size.getHeight();
AtomicReference<Dimension2D[]> repRef = new AtomicReference<>();
Dimension2D[] sizes execute(ptr -> {
= nativeGetNSImageRepresentationSizes(ptr, repRef.set(nativeGetNSImageRepresentationSizes(ptr, size.getWidth(),
size.getWidth(), size.getHeight()); size.getHeight()));
});
Dimension2D[] sizes = repRef.get();
return sizes == null || sizes.length < 2 ? return sizes == null || sizes.length < 2 ?
new MultiResolutionCachedImage(w, h, (width, height) new MultiResolutionCachedImage(w, h, (width, height)
...@@ -256,18 +268,18 @@ public class CImage extends CFRetainedResource { ...@@ -256,18 +268,18 @@ public class CImage extends CFRetainedResource {
final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE); final BufferedImage bimg = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB_PRE);
final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer(); final DataBufferInt dbi = (DataBufferInt)bimg.getRaster().getDataBuffer();
final int[] buffer = SunWritableRaster.stealData(dbi, 0); final int[] buffer = SunWritableRaster.stealData(dbi, 0);
nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight); execute(ptr->nativeCopyNSImageIntoArray(ptr, buffer, srcWidth, srcHeight, dstWidth, dstHeight));
SunWritableRaster.markDirty(dbi); SunWritableRaster.markDirty(dbi);
return bimg; return bimg;
} }
/** If nsImagePtr != 0 then scale this NSImage. @return *this* */ /** If nsImagePtr != 0 then scale this NSImage. @return *this* */
CImage resize(final double w, final double h) { CImage resize(final double w, final double h) {
if (ptr != 0) nativeSetNSImageSize(ptr, w, h); execute(ptr -> nativeSetNSImageSize(ptr, w, h));
return this; return this;
} }
void resizeRepresentations(double w, double h) { void resizeRepresentations(double w, double h) {
if (ptr != 0) nativeResizeNSImageRepresentations(ptr, w, h); execute(ptr -> nativeResizeNSImageRepresentations(ptr, w, h));
} }
} }
...@@ -113,7 +113,13 @@ public class CMenuItem extends CMenuComponent implements MenuItemPeer { ...@@ -113,7 +113,13 @@ public class CMenuItem extends CMenuComponent implements MenuItemPeer {
*/ */
public final void setImage(final java.awt.Image img) { public final void setImage(final java.awt.Image img) {
CImage cimg = CImage.getCreator().createFromImage(img); CImage cimg = CImage.getCreator().createFromImage(img);
execute(ptr -> nativeSetImage(ptr, cimg == null ? 0L : cimg.ptr)); execute(ptr -> {
if (cimg == null) {
nativeSetImage(ptr, 0L);
} else {
cimg.execute(imgPtr -> nativeSetImage(ptr, imgPtr));
}
});
} }
/** /**
......
/* /*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,6 +44,9 @@ class CPlatformComponent extends CFRetainedResource ...@@ -44,6 +44,9 @@ class CPlatformComponent extends CFRetainedResource
super(0, true); super(0, true);
} }
/**
* Used by JAWT.
*/
public long getPointer() { public long getPointer() {
return ptr; return ptr;
} }
...@@ -61,7 +64,7 @@ class CPlatformComponent extends CFRetainedResource ...@@ -61,7 +64,7 @@ class CPlatformComponent extends CFRetainedResource
// translates values from the coordinate system of the top-level window // translates values from the coordinate system of the top-level window
// to the coordinate system of the content view // to the coordinate system of the content view
final Insets insets = platformWindow.getPeer().getInsets(); final Insets insets = platformWindow.getPeer().getInsets();
nativeSetBounds(getPointer(), x - insets.left, y - insets.top, w, h); execute(ptr->nativeSetBounds(ptr, x - insets.left, y - insets.top, w, h));
} }
@Override @Override
......
...@@ -107,11 +107,6 @@ public class CPlatformLWWindow extends CPlatformWindow { ...@@ -107,11 +107,6 @@ public class CPlatformLWWindow extends CPlatformWindow {
public void updateIconImages() { public void updateIconImages() {
} }
@Override
public long getNSWindowPtr() {
return 0;
}
@Override @Override
public SurfaceData getSurfaceData() { public SurfaceData getSurfaceData() {
return null; return null;
......
/* /*
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,9 @@ package sun.lwawt.macosx; ...@@ -27,6 +27,9 @@ package sun.lwawt.macosx;
import java.awt.*; import java.awt.*;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsConfig;
import sun.awt.CGraphicsEnvironment; import sun.awt.CGraphicsEnvironment;
...@@ -83,7 +86,7 @@ public class CPlatformView extends CFRetainedResource { ...@@ -83,7 +86,7 @@ public class CPlatformView extends CFRetainedResource {
* Cocoa coordinates). * Cocoa coordinates).
*/ */
public void setBounds(int x, int y, int width, int height) { public void setBounds(int x, int y, int width, int height) {
CWrapper.NSView.setFrame(ptr, x, y, width, height); execute(ptr->CWrapper.NSView.setFrame(ptr, x, y, width, height));
} }
// REMIND: CGLSurfaceData expects top-level's size // REMIND: CGLSurfaceData expects top-level's size
...@@ -96,7 +99,7 @@ public class CPlatformView extends CFRetainedResource { ...@@ -96,7 +99,7 @@ public class CPlatformView extends CFRetainedResource {
} }
public void setToolTip(String msg) { public void setToolTip(String msg) {
CWrapper.NSView.setToolTip(ptr, msg); execute(ptr -> CWrapper.NSView.setToolTip(ptr, msg));
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
...@@ -147,18 +150,25 @@ public class CPlatformView extends CFRetainedResource { ...@@ -147,18 +150,25 @@ public class CPlatformView extends CFRetainedResource {
} }
public void setAutoResizable(boolean toResize) { public void setAutoResizable(boolean toResize) {
nativeSetAutoResizable(this.getAWTView(), toResize); execute(ptr -> nativeSetAutoResizable(ptr, toResize));
} }
public boolean isUnderMouse() { public boolean isUnderMouse() {
return nativeIsViewUnderMouse(getAWTView()); AtomicBoolean ref = new AtomicBoolean();
execute(ptr -> {
ref.set(nativeIsViewUnderMouse(ptr));
});
return ref.get();
} }
public GraphicsDevice getGraphicsDevice() { public GraphicsDevice getGraphicsDevice() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
CGraphicsEnvironment cge = (CGraphicsEnvironment)ge; CGraphicsEnvironment cge = (CGraphicsEnvironment)ge;
int displayID = nativeGetNSViewDisplayID(getAWTView()); AtomicInteger ref = new AtomicInteger();
GraphicsDevice gd = cge.getScreenDevice(displayID); execute(ptr -> {
ref.set(nativeGetNSViewDisplayID(ptr));
});
GraphicsDevice gd = cge.getScreenDevice(ref.get());
if (gd == null) { if (gd == null) {
// this could possibly happen during device removal // this could possibly happen during device removal
// use the default screen device in this case // use the default screen device in this case
...@@ -168,9 +178,16 @@ public class CPlatformView extends CFRetainedResource { ...@@ -168,9 +178,16 @@ public class CPlatformView extends CFRetainedResource {
} }
public Point getLocationOnScreen() { public Point getLocationOnScreen() {
Rectangle r = nativeGetLocationOnScreen(this.getAWTView()).getBounds(); AtomicReference<Rectangle> ref = new AtomicReference<>();
execute(ptr -> {
ref.set(nativeGetLocationOnScreen(ptr).getBounds());
});
Rectangle r = ref.get();
if (r != null) {
return new Point(r.x, r.y); return new Point(r.x, r.y);
} }
return new Point(0, 0);
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// NATIVE CALLBACKS // NATIVE CALLBACKS
......
...@@ -31,6 +31,9 @@ import java.awt.event.*; ...@@ -31,6 +31,9 @@ import java.awt.event.*;
import java.awt.peer.WindowPeer; import java.awt.peer.WindowPeer;
import java.beans.*; import java.beans.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -178,16 +181,16 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -178,16 +181,16 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString())); c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString()));
}}, }},
new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) { new Property<CPlatformWindow>(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) {
nativeRevalidateNSWindowShadow(c.getNSWindowPtr()); c.execute(ptr -> nativeRevalidateNSWindowShadow(ptr));
}}, }},
new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) { new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
if (value == null || !(value instanceof java.io.File)) { if (value == null || !(value instanceof java.io.File)) {
nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), null); c.execute(ptr->nativeSetNSWindowRepresentedFilename(ptr, null));
return; return;
} }
final String filename = ((java.io.File)value).getAbsolutePath(); final String filename = ((java.io.File)value).getAbsolutePath();
nativeSetNSWindowRepresentedFilename(c.getNSWindowPtr(), filename); c.execute(ptr->nativeSetNSWindowRepresentedFilename(ptr, filename));
}} }}
}) { }) {
public CPlatformWindow convertJComponentToTarget(final JRootPane p) { public CPlatformWindow convertJComponentToTarget(final JRootPane p) {
...@@ -232,7 +235,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -232,7 +235,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
contentView = createContentView(); contentView = createContentView();
contentView.initialize(peer, responder); contentView.initialize(peer, responder);
final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L;
Rectangle bounds; Rectangle bounds;
if (!IS(DECORATED, styleBits)) { if (!IS(DECORATED, styleBits)) {
// For undecorated frames the move/resize event does not come if the frame is centered on the screen // For undecorated frames the move/resize event does not come if the frame is centered on the screen
...@@ -241,9 +243,21 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -241,9 +243,21 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
} else { } else {
bounds = _peer.constrainBounds(_target.getBounds()); bounds = _peer.constrainBounds(_target.getBounds());
} }
final long nativeWindowPtr = nativeCreateNSWindow(contentView.getAWTView(), AtomicLong ref = new AtomicLong();
ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height); contentView.execute(viewPtr -> {
setPtr(nativeWindowPtr); if (owner != null) {
owner.execute(ownerPtr -> {
ref.set(nativeCreateNSWindow(viewPtr, ownerPtr, styleBits,
bounds.x, bounds.y,
bounds.width, bounds.height));
});
} else {
ref.set(nativeCreateNSWindow(viewPtr, 0,
styleBits, bounds.x, bounds.y,
bounds.width, bounds.height));
}
});
setPtr(ref.get());
if (target instanceof javax.swing.RootPaneContainer) { if (target instanceof javax.swing.RootPaneContainer) {
final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane(); final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer)target).getRootPane();
...@@ -405,30 +419,31 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -405,30 +419,31 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// this is the counter-point to -[CWindow _nativeSetStyleBit:] // this is the counter-point to -[CWindow _nativeSetStyleBit:]
private void setStyleBits(final int mask, final boolean value) { private void setStyleBits(final int mask, final boolean value) {
nativeSetNSWindowStyleBits(getNSWindowPtr(), mask, value ? mask : 0); execute(ptr -> nativeSetNSWindowStyleBits(ptr, mask, value ? mask : 0));
} }
private native void _toggleFullScreenMode(final long model); private native void _toggleFullScreenMode(final long model);
public void toggleFullScreen() { public void toggleFullScreen() {
_toggleFullScreenMode(getNSWindowPtr()); execute(this::_toggleFullScreenMode);
} }
@Override // PlatformWindow @Override // PlatformWindow
public void setMenuBar(MenuBar mb) { public void setMenuBar(MenuBar mb) {
final long nsWindowPtr = getNSWindowPtr();
CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb); CMenuBar mbPeer = (CMenuBar)LWToolkit.targetToPeer(mb);
execute(nsWindowPtr->{
if (mbPeer != null) { if (mbPeer != null) {
mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr)); mbPeer.execute(ptr -> nativeSetNSWindowMenuBar(nsWindowPtr, ptr));
} else { } else {
nativeSetNSWindowMenuBar(nsWindowPtr, 0); nativeSetNSWindowMenuBar(nsWindowPtr, 0);
} }
});
} }
@Override // PlatformWindow @Override // PlatformWindow
public void dispose() { public void dispose() {
contentView.dispose(); contentView.dispose();
nativeDispose(getNSWindowPtr()); execute(CPlatformWindow::nativeDispose);
CPlatformWindow.super.dispose(); CPlatformWindow.super.dispose();
} }
...@@ -441,7 +456,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -441,7 +456,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override // PlatformWindow @Override // PlatformWindow
public Insets getInsets() { public Insets getInsets() {
return nativeGetNSWindowInsets(getNSWindowPtr()); AtomicReference<Insets> ref = new AtomicReference<>();
execute(ptr -> {
ref.set(nativeGetNSWindowInsets(ptr));
});
return ref.get() != null ? ref.get() : new Insets(0, 0, 0, 0);
} }
@Override // PlatformWindow @Override // PlatformWindow
...@@ -468,12 +487,18 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -468,12 +487,18 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override // PlatformWindow @Override // PlatformWindow
public void setBounds(int x, int y, int w, int h) { public void setBounds(int x, int y, int w, int h) {
// assert CThreading.assertEventQueue(); // assert CThreading.assertEventQueue();
nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h); execute(ptr -> nativeSetNSWindowBounds(ptr, x, y, w, h));
} }
private boolean isMaximized() { private boolean isMaximized() {
return undecorated ? this.normalBounds != null if (undecorated) {
: CWrapper.NSWindow.isZoomed(getNSWindowPtr()); return this.normalBounds != null;
}
AtomicBoolean ref = new AtomicBoolean();
execute(ptr -> {
ref.set(CWrapper.NSWindow.isZoomed(ptr));
});
return ref.get();
} }
private void maximize() { private void maximize() {
...@@ -481,7 +506,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -481,7 +506,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
return; return;
} }
if (!undecorated) { if (!undecorated) {
CWrapper.NSWindow.zoom(getNSWindowPtr()); execute(CWrapper.NSWindow::zoom);
} else { } else {
deliverZoom(true); deliverZoom(true);
...@@ -505,7 +530,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -505,7 +530,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
return; return;
} }
if (!undecorated) { if (!undecorated) {
CWrapper.NSWindow.zoom(getNSWindowPtr()); execute(CWrapper.NSWindow::zoom);
} else { } else {
deliverZoom(false); deliverZoom(false);
...@@ -521,8 +546,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -521,8 +546,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override // PlatformWindow @Override // PlatformWindow
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
final long nsWindowPtr = getNSWindowPtr();
// Configure stuff // Configure stuff
updateIconImages(); updateIconImages();
updateFocusabilityForAutoRequestFocus(false); updateFocusabilityForAutoRequestFocus(false);
...@@ -534,30 +557,44 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -534,30 +557,44 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if (blocker == null || !visible) { if (blocker == null || !visible) {
// If it ain't blocked, or is being hidden, go regular way // If it ain't blocked, or is being hidden, go regular way
if (visible) { if (visible) {
CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView()); contentView.execute(viewPtr -> {
execute(ptr -> CWrapper.NSWindow.makeFirstResponder(ptr,
viewPtr));
});
boolean isPopup = (target.getType() == Window.Type.POPUP); boolean isPopup = (target.getType() == Window.Type.POPUP);
execute(ptr -> {
if (isPopup) { if (isPopup) {
// Popups in applets don't activate applet's process // Popups in applets don't activate applet's process
CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr); CWrapper.NSWindow.orderFrontRegardless(ptr);
} else { } else {
CWrapper.NSWindow.orderFront(nsWindowPtr); CWrapper.NSWindow.orderFront(ptr);
} }
boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr); boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(ptr);
if (!isKeyWindow) { if (!isKeyWindow) {
CWrapper.NSWindow.makeKeyWindow(nsWindowPtr); CWrapper.NSWindow.makeKeyWindow(ptr);
} }
});
} else { } else {
execute(ptr->{
// immediately hide the window // immediately hide the window
CWrapper.NSWindow.orderOut(nsWindowPtr); CWrapper.NSWindow.orderOut(ptr);
// process the close // process the close
CWrapper.NSWindow.close(nsWindowPtr); CWrapper.NSWindow.close(ptr);
});
} }
} else { } else {
// otherwise, put it in a proper z-order // otherwise, put it in a proper z-order
CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow, CPlatformWindow bw
((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr()); = (CPlatformWindow) blocker.getPlatformWindow();
bw.execute(blockerPtr -> {
execute(ptr -> {
CWrapper.NSWindow.orderWindow(ptr,
CWrapper.NSWindow.NSWindowBelow,
blockerPtr);
});
});
} }
this.visible = visible; this.visible = visible;
...@@ -576,7 +613,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -576,7 +613,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
} }
switch (frameState) { switch (frameState) {
case Frame.ICONIFIED: case Frame.ICONIFIED:
CWrapper.NSWindow.miniaturize(nsWindowPtr); execute(CWrapper.NSWindow::miniaturize);
break; break;
case Frame.MAXIMIZED_BOTH: case Frame.MAXIMIZED_BOTH:
maximize(); maximize();
...@@ -598,7 +635,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -598,7 +635,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if (visible) { if (visible) {
// Order myself above my parent // Order myself above my parent
if (owner != null && owner.isVisible()) { if (owner != null && owner.isVisible()) {
CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr()); owner.execute(ownerPtr -> {
execute(ptr -> {
CWrapper.NSWindow.orderWindow(ptr, CWrapper.NSWindow.NSWindowAbove, ownerPtr);
});
});
applyWindowLevel(target); applyWindowLevel(target);
} }
...@@ -608,7 +649,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -608,7 +649,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if (p instanceof LWWindowPeer) { if (p instanceof LWWindowPeer) {
CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow(); CPlatformWindow pw = (CPlatformWindow)((LWWindowPeer)p).getPlatformWindow();
if (pw != null && pw.isVisible()) { if (pw != null && pw.isVisible()) {
CWrapper.NSWindow.orderWindow(pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove, nsWindowPtr); pw.execute(childPtr -> {
execute(ptr -> {
CWrapper.NSWindow.orderWindow(childPtr, CWrapper.NSWindow.NSWindowAbove, ptr);
});
});
pw.applyWindowLevel(w); pw.applyWindowLevel(w);
} }
} }
...@@ -624,25 +669,22 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -624,25 +669,22 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override // PlatformWindow @Override // PlatformWindow
public void setTitle(String title) { public void setTitle(String title) {
nativeSetNSWindowTitle(getNSWindowPtr(), title); execute(ptr -> nativeSetNSWindowTitle(ptr, title));
} }
// Should be called on every window key property change. // Should be called on every window key property change.
@Override // PlatformWindow @Override // PlatformWindow
public void updateIconImages() { public void updateIconImages() {
final long nsWindowPtr = getNSWindowPtr();
final CImage cImage = getImageForTarget(); final CImage cImage = getImageForTarget();
nativeSetNSWindowMinimizedIcon(nsWindowPtr, cImage == null ? 0L : cImage.ptr); execute(ptr -> {
} if (cImage == null) {
nativeSetNSWindowMinimizedIcon(ptr, 0L);
public long getNSWindowPtr() { } else {
final long nsWindowPtr = ptr; cImage.execute(imagePtr -> {
if (nsWindowPtr == 0L) { nativeSetNSWindowMinimizedIcon(ptr, imagePtr);
if(logger.isLoggable(PlatformLogger.Level.FINE)) { });
logger.fine("NSWindow already disposed?", new Exception("Pointer to native NSWindow is invalid."));
}
} }
return nsWindowPtr; });
} }
public SurfaceData getSurfaceData() { public SurfaceData getSurfaceData() {
...@@ -651,13 +693,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -651,13 +693,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override // PlatformWindow @Override // PlatformWindow
public void toBack() { public void toBack() {
final long nsWindowPtr = getNSWindowPtr(); execute(CPlatformWindow::nativePushNSWindowToBack);
nativePushNSWindowToBack(nsWindowPtr);
} }
@Override // PlatformWindow @Override // PlatformWindow
public void toFront() { public void toFront() {
final long nsWindowPtr = getNSWindowPtr();
LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit(); LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if( w != null && w.getPeer() != null if( w != null && w.getPeer() != null
...@@ -666,7 +706,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -666,7 +706,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
lwcToolkit.activateApplicationIgnoringOtherApps(); lwcToolkit.activateApplicationIgnoringOtherApps();
} }
updateFocusabilityForAutoRequestFocus(false); updateFocusabilityForAutoRequestFocus(false);
nativePushNSWindowToFront(nsWindowPtr); execute(CPlatformWindow::nativePushNSWindowToFront);
updateFocusabilityForAutoRequestFocus(true); updateFocusabilityForAutoRequestFocus(true);
} }
...@@ -677,7 +717,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -677,7 +717,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override @Override
public void setSizeConstraints(int minW, int minH, int maxW, int maxH) { public void setSizeConstraints(int minW, int minH, int maxW, int maxH) {
nativeSetNSWindowMinMax(getNSWindowPtr(), minW, minH, maxW, maxH); execute(ptr -> nativeSetNSWindowMinMax(ptr, minW, minH, maxW, maxH));
} }
@Override @Override
...@@ -694,19 +734,22 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -694,19 +734,22 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override @Override
public boolean requestWindowFocus() { public boolean requestWindowFocus() {
execute(ptr -> {
long ptr = getNSWindowPtr();
if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) { if (CWrapper.NSWindow.canBecomeMainWindow(ptr)) {
CWrapper.NSWindow.makeMainWindow(ptr); CWrapper.NSWindow.makeMainWindow(ptr);
} }
CWrapper.NSWindow.makeKeyAndOrderFront(ptr); CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
});
return true; return true;
} }
@Override @Override
public boolean isActive() { public boolean isActive() {
long ptr = getNSWindowPtr(); AtomicBoolean ref = new AtomicBoolean();
return CWrapper.NSWindow.isKeyWindow(ptr); execute(ptr -> {
ref.set(CWrapper.NSWindow.isKeyWindow(ptr));
});
return ref.get();
} }
@Override @Override
...@@ -732,21 +775,21 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -732,21 +775,21 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override @Override
public void setOpacity(float opacity) { public void setOpacity(float opacity) {
CWrapper.NSWindow.setAlphaValue(getNSWindowPtr(), opacity); execute(ptr -> CWrapper.NSWindow.setAlphaValue(ptr, opacity));
} }
@Override @Override
public void setOpaque(boolean isOpaque) { public void setOpaque(boolean isOpaque) {
CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque); execute(ptr -> CWrapper.NSWindow.setOpaque(ptr, isOpaque));
boolean isTextured = (peer == null) ? false : peer.isTextured(); boolean isTextured = (peer == null) ? false : peer.isTextured();
if (!isTextured) { if (!isTextured) {
if (!isOpaque) { if (!isOpaque) {
CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), 0); execute(ptr -> CWrapper.NSWindow.setBackgroundColor(ptr, 0));
} else if (peer != null) { } else if (peer != null) {
Color color = peer.getBackground(); Color color = peer.getBackground();
if (color != null) { if (color != null) {
int rgb = color.getRGB(); int rgb = color.getRGB();
CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), rgb); execute(ptr->CWrapper.NSWindow.setBackgroundColor(ptr, rgb));
} }
} }
} }
...@@ -759,12 +802,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -759,12 +802,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override @Override
public void enterFullScreenMode() { public void enterFullScreenMode() {
isFullScreenMode = true; isFullScreenMode = true;
nativeEnterFullScreenMode(getNSWindowPtr()); execute(CPlatformWindow::nativeEnterFullScreenMode);
} }
@Override @Override
public void exitFullScreenMode() { public void exitFullScreenMode() {
nativeExitFullScreenMode(getNSWindowPtr()); execute(CPlatformWindow::nativeExitFullScreenMode);
isFullScreenMode = false; isFullScreenMode = false;
} }
...@@ -783,7 +826,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -783,7 +826,6 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
int prevWindowState = peer.getState(); int prevWindowState = peer.getState();
if (prevWindowState == windowState) return; if (prevWindowState == windowState) return;
final long nsWindowPtr = getNSWindowPtr();
if ((windowState & Frame.ICONIFIED) != 0) { if ((windowState & Frame.ICONIFIED) != 0) {
// Treat all state bit masks with ICONIFIED bit as ICONIFIED state. // Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
windowState = Frame.ICONIFIED; windowState = Frame.ICONIFIED;
...@@ -795,18 +837,18 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -795,18 +837,18 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// the zoom call toggles between the normal and the max states // the zoom call toggles between the normal and the max states
unmaximize(); unmaximize();
} }
CWrapper.NSWindow.miniaturize(nsWindowPtr); execute(CWrapper.NSWindow::miniaturize);
break; break;
case Frame.MAXIMIZED_BOTH: case Frame.MAXIMIZED_BOTH:
if (prevWindowState == Frame.ICONIFIED) { if (prevWindowState == Frame.ICONIFIED) {
// let's return into the normal states first // let's return into the normal states first
CWrapper.NSWindow.deminiaturize(nsWindowPtr); execute(CWrapper.NSWindow::deminiaturize);
} }
maximize(); maximize();
break; break;
case Frame.NORMAL: case Frame.NORMAL:
if (prevWindowState == Frame.ICONIFIED) { if (prevWindowState == Frame.ICONIFIED) {
CWrapper.NSWindow.deminiaturize(nsWindowPtr); execute(CWrapper.NSWindow::deminiaturize);
} else if (prevWindowState == Frame.MAXIMIZED_BOTH) { } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
// the zoom call toggles between the normal and the max states // the zoom call toggles between the normal and the max states
unmaximize(); unmaximize();
...@@ -826,12 +868,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -826,12 +868,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
return; return;
} }
nativeSetEnabled(getNSWindowPtr(), !blocked); execute(ptr -> nativeSetEnabled(ptr, !blocked));
checkBlockingAndOrder(); checkBlockingAndOrder();
} }
public final void invalidateShadow(){ public final void invalidateShadow(){
nativeRevalidateNSWindowShadow(getNSWindowPtr()); execute(ptr -> nativeRevalidateNSWindowShadow(ptr));
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
...@@ -1011,11 +1053,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -1011,11 +1053,11 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
pWindow.orderAboveSiblings(); pWindow.orderAboveSiblings();
final long nsWindowPtr = pWindow.getNSWindowPtr(); pWindow.execute(ptr -> {
CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr); CWrapper.NSWindow.orderFrontRegardless(ptr);
CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr); CWrapper.NSWindow.makeKeyAndOrderFront(ptr);
CWrapper.NSWindow.makeMainWindow(nsWindowPtr); CWrapper.NSWindow.makeMainWindow(ptr);
});
return true; return true;
} }
...@@ -1035,10 +1077,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -1035,10 +1077,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
owner.orderAboveSiblings(); owner.orderAboveSiblings();
// Order the window to front of the stack of child windows // Order the window to front of the stack of child windows
final long nsWindowSelfPtr = getNSWindowPtr(); owner.execute(nsWindowOwnerPtr->{
final long nsWindowOwnerPtr = owner.getNSWindowPtr(); execute(nsWindowSelfPtr->{
CWrapper.NSWindow.orderFront(nsWindowOwnerPtr); CWrapper.NSWindow.orderFront(nsWindowOwnerPtr);
CWrapper.NSWindow.orderWindow(nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove, nsWindowOwnerPtr); CWrapper.NSWindow.orderWindow(nsWindowSelfPtr, CWrapper.NSWindow.NSWindowAbove, nsWindowOwnerPtr);
});
});
} }
applyWindowLevel(target); applyWindowLevel(target);
...@@ -1046,9 +1090,9 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -1046,9 +1090,9 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
protected void applyWindowLevel(Window target) { protected void applyWindowLevel(Window target) {
if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) { if (target.isAlwaysOnTop() && target.getType() != Window.Type.POPUP) {
CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSFloatingWindowLevel); execute(ptr->CWrapper.NSWindow.setLevel(ptr, CWrapper.NSWindow.NSFloatingWindowLevel));
} else if (target.getType() == Window.Type.POPUP) { } else if (target.getType() == Window.Type.POPUP) {
CWrapper.NSWindow.setLevel(getNSWindowPtr(), CWrapper.NSWindow.NSPopUpMenuWindowLevel); execute(ptr->CWrapper.NSWindow.setLevel(ptr, CWrapper.NSWindow.NSPopUpMenuWindowLevel));
} }
} }
......
...@@ -36,6 +36,7 @@ import java.awt.image.BufferedImage; ...@@ -36,6 +36,7 @@ import java.awt.image.BufferedImage;
import java.awt.peer.TrayIconPeer; import java.awt.peer.TrayIconPeer;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.concurrent.atomic.AtomicReference;
public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
private TrayIcon target; private TrayIcon target;
...@@ -88,10 +89,6 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { ...@@ -88,10 +89,6 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
return nativeCreate(); return nativeCreate();
} }
private long getModel() {
return ptr;
}
private native long nativeCreate(); private native long nativeCreate();
//invocation from the AWTTrayIcon.m //invocation from the AWTTrayIcon.m
...@@ -154,7 +151,7 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { ...@@ -154,7 +151,7 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
@Override @Override
public void setToolTip(String tooltip) { public void setToolTip(String tooltip) {
nativeSetToolTip(getModel(), tooltip); execute(ptr -> nativeSetToolTip(ptr, tooltip));
} }
//adds tooltip to the NSStatusBar's NSButton. //adds tooltip to the NSStatusBar's NSButton.
...@@ -183,7 +180,12 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { ...@@ -183,7 +180,12 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
} }
CImage cimage = CImage.getCreator().createFromImage(image); CImage cimage = CImage.getCreator().createFromImage(image);
setNativeImage(getModel(), cimage.ptr, target.isImageAutoSize()); boolean imageAutoSize = target.isImageAutoSize();
cimage.execute(imagePtr -> {
execute(ptr -> {
setNativeImage(ptr, imagePtr, imageAutoSize);
});
});
} }
private native void setNativeImage(final long model, final long nsimage, final boolean autosize); private native void setNativeImage(final long model, final long nsimage, final boolean autosize);
...@@ -363,7 +365,14 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { ...@@ -363,7 +365,14 @@ public class CTrayIcon extends CFRetainedResource implements TrayIconPeer {
private void showMessageDialog() { private void showMessageDialog() {
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Point2D iconLoc = nativeGetIconLocation(getModel()); AtomicReference<Point2D> ref = new AtomicReference<>();
execute(ptr -> {
ref.set(nativeGetIconLocation(ptr));
});
Point2D iconLoc = ref.get();
if (iconLoc == null) {
return;
}
int dialogY = (int)iconLoc.getY(); int dialogY = (int)iconLoc.getY();
int dialogX = (int)iconLoc.getX(); int dialogX = (int)iconLoc.getX();
......
...@@ -74,13 +74,13 @@ public class CViewPlatformEmbeddedFrame implements PlatformWindow { ...@@ -74,13 +74,13 @@ public class CViewPlatformEmbeddedFrame implements PlatformWindow {
@Override @Override
public void dispose() { public void dispose() {
CWrapper.NSView.removeFromSuperview(view.getAWTView()); view.execute(CWrapper.NSView::removeFromSuperview);
view.dispose(); view.dispose();
} }
@Override @Override
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
CWrapper.NSView.setHidden(view.getAWTView(), !visible); view.execute(ptr -> CWrapper.NSView.setHidden(ptr, !visible));
} }
@Override @Override
......
...@@ -219,14 +219,14 @@ public final class CWarningWindow extends CPlatformWindow ...@@ -219,14 +219,14 @@ public final class CWarningWindow extends CPlatformWindow
@Override @Override
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
synchronized (lock) { synchronized (lock) {
final long nsWindowPtr = getNSWindowPtr(); execute(ptr -> {
// Actually show or hide the window // Actually show or hide the window
if (visible) { if (visible) {
CWrapper.NSWindow.orderFront(nsWindowPtr); CWrapper.NSWindow.orderFront(ptr);
} else { } else {
CWrapper.NSWindow.orderOut(nsWindowPtr); CWrapper.NSWindow.orderOut(ptr);
} }
});
this.visible = visible; this.visible = visible;
...@@ -234,8 +234,13 @@ public final class CWarningWindow extends CPlatformWindow ...@@ -234,8 +234,13 @@ public final class CWarningWindow extends CPlatformWindow
if (visible) { if (visible) {
// Order myself above my parent // Order myself above my parent
if (owner != null && owner.isVisible()) { if (owner != null && owner.isVisible()) {
CWrapper.NSWindow.orderWindow(nsWindowPtr, owner.execute(ownerPtr -> {
CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr()); execute(ptr -> {
CWrapper.NSWindow.orderWindow(ptr,
CWrapper.NSWindow.NSWindowAbove,
ownerPtr);
});
});
// do not allow security warning to be obscured by other windows // do not allow security warning to be obscured by other windows
applyWindowLevel(ownerWindow); applyWindowLevel(ownerWindow);
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
CALayer *windowLayer; CALayer *windowLayer;
} }
@property (retain) CALayer *windowLayer;
- (id) initWithWindowLayer: (CALayer *)windowLayer; - (id) initWithWindowLayer: (CALayer *)windowLayer;
- (void) setBounds: (CGRect)rect; - (void) setBounds: (CGRect)rect;
......
...@@ -38,11 +38,15 @@ ...@@ -38,11 +38,15 @@
self = [super init]; self = [super init];
if (self == nil) return self; if (self == nil) return self;
windowLayer = aWindowLayer; self.windowLayer = aWindowLayer;
return self; return self;
} }
- (void) dealloc {
self.windowLayer = nil;
[super dealloc];
}
- (CALayer *) layer { - (CALayer *) layer {
return layer; return layer;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册